summaryrefslogtreecommitdiff
path: root/src/ltm.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-24 20:44:34 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-27 22:43:18 +1000
commited0518f417a61b32e531f85c434b8024859202cd (patch)
tree39df7684f14774877a6c454d125e23b28cb5dd18 /src/ltm.js
parent1428582c2d88b23f12c87921381796d03b388d9f (diff)
downloadfengari-ed0518f417a61b32e531f85c434b8024859202cd.tar.gz
fengari-ed0518f417a61b32e531f85c434b8024859202cd.tar.bz2
fengari-ed0518f417a61b32e531f85c434b8024859202cd.zip
Modify stack values up to L.top instead of replacing
Diffstat (limited to 'src/ltm.js')
-rw-r--r--src/ltm.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/ltm.js b/src/ltm.js
index c3efc1e..8f4908c 100644
--- a/src/ltm.js
+++ b/src/ltm.js
@@ -110,13 +110,12 @@ const luaT_objtypename = function(L, o) {
const luaT_callTM = function(L, f, p1, p2, p3, hasres) {
let func = L.top;
- lobject.setobj2s(L, L.top, f); /* push function (assume EXTRA_STACK) */
- lobject.setobj2s(L, L.top + 1, p1); /* 1st argument */
- lobject.setobj2s(L, L.top + 2, p2); /* 2nd argument */
- L.top += 3;
+ lobject.pushobj2s(L, f); /* push function (assume EXTRA_STACK) */
+ lobject.pushobj2s(L, p1); /* 1st argument */
+ lobject.pushobj2s(L, p2); /* 2nd argument */
if (!hasres) /* no result? 'p3' is third argument */
- lobject.setobj2s(L, L.top++, p3); /* 3rd argument */
+ lobject.pushobj2s(L, p3); /* 3rd argument */
if (L.ci.callstatus & lstate.CIST_LUA)
ldo.luaD_call(L, func, hasres);
@@ -124,7 +123,9 @@ const luaT_callTM = function(L, f, p1, p2, p3, hasres) {
ldo.luaD_callnoyield(L, func, hasres);
if (hasres) { /* if has result, move it to its place */
- lobject.setobjs2s(L, p3, --L.top);
+ let tv = L.stack[L.top-1];
+ delete L.stack[--L.top];
+ p3.setfrom(tv);
}
};
@@ -158,10 +159,11 @@ const luaT_trybinTM = function(L, p1, p2, res, event) {
};
const luaT_callorderTM = function(L, p1, p2, event) {
- if (!luaT_callbinTM(L, p1, p2, L.top, event))
+ let res = new lobject.TValue(CT.LUA_TNIL, null);
+ if (!luaT_callbinTM(L, p1, p2, res, event))
return -1;
else
- return !L.stack[L.top].l_isfalse() ? 1 : 0;
+ return res.l_isfalse() ? 0 : 1;
};
const fasttm = function(l, et, e) {