diff options
-rw-r--r-- | src/lvm.js | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -971,13 +971,18 @@ const luaV_concat = function(L, total) { delete L.stack[top - 1]; } else { /* at least two non-empty string values; get as many as possible */ - let concatenated = L.stack[top-1].svalue(); + let toconcat = new Array(total); + toconcat[total-1] = L.stack[top-1].svalue(); delete L.stack[top - 1]; - for (n = 1; n < total && tostring(L, top - n - 1); n++) { - concatenated = L.stack[top - n - 1].svalue().concat(concatenated); + for (n = 1; n < total; n++) { + if (!tostring(L, top - n - 1)) { + toconcat = toconcat.slice(total-n); + break; + } + toconcat[total-n-1] = L.stack[top - n - 1].svalue(); delete L.stack[top - n - 1]; } - let ts = lstring.luaS_bless(L, concatenated); + let ts = lstring.luaS_bless(L, Array.prototype.concat.apply([], toconcat)); L.stack[top - n] = new lobject.TValue(CT.LUA_TLNGSTR, ts); } total -= n - 1; /* got 'n' strings to create 1 new */ |