'luaV_concat' can "concat" one single value

Several of its callers needed that case and had to do the check
themselves.
This commit is contained in:
Roberto Ierusalimschy
2020-07-03 11:54:58 -03:00
parent e96385aded
commit ae809e9fd1
3 changed files with 9 additions and 14 deletions

8
lapi.c
View File

@@ -1239,14 +1239,12 @@ LUA_API void lua_toclose (lua_State *L, int idx) {
LUA_API void lua_concat (lua_State *L, int n) {
lua_lock(L);
api_checknelems(L, n);
if (n >= 2) {
if (n > 0)
luaV_concat(L, n);
}
else if (n == 0) { /* push empty string */
setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
else { /* nothing to concatenate */
setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */
api_incr_top(L);
}
/* else n == 1; nothing to do */
luaC_checkGC(L);
lua_unlock(L);
}