summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-09 14:40:07 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-09 15:21:15 +1000
commitdd087be6f10daf6dae87be07458dfaddb967edd1 (patch)
tree7a4b344fd41ff8dff1d62b00d0f6338e98a91863 /src
parent38e69595be760ead9fa4da7ac714c095e9f095b3 (diff)
downloadfengari-dd087be6f10daf6dae87be07458dfaddb967edd1.tar.gz
fengari-dd087be6f10daf6dae87be07458dfaddb967edd1.tar.bz2
fengari-dd087be6f10daf6dae87be07458dfaddb967edd1.zip
src/lvm.js: In luaV_concat use correct stack indices + clean up
Diffstat (limited to 'src')
-rw-r--r--src/lvm.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 760f686..eba7d38 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -995,21 +995,26 @@ const luaV_concat = function(L, total) {
let top = L.top;
let n = 2; /* number of elements handled in this pass (at least 2) */
- if (!(L.stack[top-2].ttisstring() || L.stack[top-2].ttisnumber()) || !tostring(L, top - 1))
+ if (!(L.stack[top-2].ttisstring() || L.stack[top-2].ttisnumber()) || !tostring(L, top - 1)) {
ltm.luaT_trybinTM(L, L.stack[top-2], L.stack[top-1], top-2, ltm.TMS.TM_CONCAT);
- else if (isemptystr(L.stack[top-1])) {
+ delete L.stack[top - 1];
+ } else if (isemptystr(L.stack[top-1])) {
tostring(L, top - 2);
+ delete L.stack[top - 1];
} else if (isemptystr(L.stack[top-2])) {
L.stack[top - 2] = L.stack[top - 1];
+ delete L.stack[top - 1];
} else {
/* at least two non-empty string values; get as many as possible */
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++) {
toconcat[total-n-1] = L.stack[top - n - 1].svalue();
+ delete L.stack[top - n - 1];
}
let ts = lstring.luaS_bless(L, Array.prototype.concat.apply([], toconcat));
- L.stack[top - total] = new lobject.TValue(CT.LUA_TLNGSTR, ts);
+ L.stack[top - n] = new lobject.TValue(CT.LUA_TLNGSTR, ts);
}
total -= n - 1; /* got 'n' strings to create 1 new */
L.top -= n - 1; /* popped 'n' strings and pushed one */