mirror of https://github.com/rusefi/lua.git
'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:
parent
e96385aded
commit
ae809e9fd1
8
lapi.c
8
lapi.c
|
@ -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_API void lua_concat (lua_State *L, int n) {
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
api_checknelems(L, n);
|
api_checknelems(L, n);
|
||||||
if (n >= 2) {
|
if (n > 0)
|
||||||
luaV_concat(L, n);
|
luaV_concat(L, n);
|
||||||
}
|
else { /* nothing to concatenate */
|
||||||
else if (n == 0) { /* push empty string */
|
setsvalue2s(L, L->top, luaS_newlstr(L, "", 0)); /* push empty string */
|
||||||
setsvalue2s(L, L->top, luaS_newlstr(L, "", 0));
|
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
}
|
}
|
||||||
/* else n == 1; nothing to do */
|
|
||||||
luaC_checkGC(L);
|
luaC_checkGC(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,10 +402,8 @@ static void pushstr (BuffFS *buff, const char *str, size_t l) {
|
||||||
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
|
setsvalue2s(L, L->top, luaS_newlstr(L, str, l));
|
||||||
L->top++; /* may use one extra slot */
|
L->top++; /* may use one extra slot */
|
||||||
buff->pushed++;
|
buff->pushed++;
|
||||||
if (buff->pushed > 1) {
|
|
||||||
luaV_concat(L, buff->pushed); /* join partial results into one */
|
luaV_concat(L, buff->pushed); /* join partial results into one */
|
||||||
buff->pushed = 1;
|
buff->pushed = 1;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
5
lvm.c
5
lvm.c
|
@ -634,7 +634,8 @@ static void copy2buff (StkId top, int n, char *buff) {
|
||||||
** from 'L->top - total' up to 'L->top - 1'.
|
** from 'L->top - total' up to 'L->top - 1'.
|
||||||
*/
|
*/
|
||||||
void luaV_concat (lua_State *L, int total) {
|
void luaV_concat (lua_State *L, int total) {
|
||||||
lua_assert(total >= 2);
|
if (total == 1)
|
||||||
|
return; /* "all" values already concatenated */
|
||||||
do {
|
do {
|
||||||
StkId top = L->top;
|
StkId top = L->top;
|
||||||
int n = 2; /* number of elements handled in this pass (at least 2) */
|
int n = 2; /* number of elements handled in this pass (at least 2) */
|
||||||
|
@ -840,10 +841,8 @@ void luaV_finishOp (lua_State *L) {
|
||||||
int a = GETARG_A(inst); /* first element to concatenate */
|
int a = GETARG_A(inst); /* first element to concatenate */
|
||||||
int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */
|
int total = cast_int(top - 1 - (base + a)); /* yet to concatenate */
|
||||||
setobjs2s(L, top - 2, top); /* put TM result in proper position */
|
setobjs2s(L, top - 2, top); /* put TM result in proper position */
|
||||||
if (total > 1) { /* are there elements to concat? */
|
|
||||||
L->top = top - 1; /* top is one after last element (at top-2) */
|
L->top = top - 1; /* top is one after last element (at top-2) */
|
||||||
luaV_concat(L, total); /* concat them (may yield again) */
|
luaV_concat(L, total); /* concat them (may yield again) */
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
Loading…
Reference in New Issue