summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-23 17:37:20 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-27 22:14:35 +1000
commit888c1286cfe25c1b21605c3443cc0a20b522972b (patch)
tree803c8a31cccbb5013539fd0a575cc10f6af5a7fb /src/lapi.js
parentb3c87776e08f546a9994527f7c2c7fc4ec07d9a1 (diff)
downloadfengari-888c1286cfe25c1b21605c3443cc0a20b522972b.tar.gz
fengari-888c1286cfe25c1b21605c3443cc0a20b522972b.tar.bz2
fengari-888c1286cfe25c1b21605c3443cc0a20b522972b.zip
Introduce setobj2s
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 00e608f..2cf3a1c 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -112,7 +112,7 @@ const lua_xmove = function(from, to, n) {
from.top -= n;
for (let i = 0; i < n; i++) {
- to.stack[to.top] = from.stack[from.top + i];
+ lobject.setobj2s(to, to.top, from.stack[from.top + i]);
to.top++;
}
};
@@ -135,8 +135,7 @@ const lua_gettop = function(L) {
};
const lua_pushvalue = function(L, idx) {
- L.stack[L.top] = index2addr(L, idx);
-
+ lobject.setobj2s(L, L.top, index2addr(L, idx));
L.top++;
assert(L.top <= L.ci.top, "stack overflow");
};
@@ -164,7 +163,7 @@ const reverse = function(L, from, to) {
for (; from < to; from++, to--) {
let temp = L.stack[from];
lobject.setobjs2s(L, from, to);
- L.stack[to] = temp;
+ lobject.setobj2s(L, to, temp);
}
};
@@ -474,12 +473,10 @@ const auxgetstr = function(L, t, k) {
const lua_rawgeti = function(L, idx, n) {
let t = index2addr(L, idx);
-
assert(t.ttistable(), "table expected");
-
- L.stack[L.top++] = ltable.luaH_getint(t.value, n);
+ lobject.setobj2s(L, L.top, ltable.luaH_getint(t.value, n));
+ L.top++;
assert(L.top <= L.ci.top, "stack overflow");
-
return L.stack[L.top - 1].ttnov();
};
@@ -487,18 +484,16 @@ const lua_rawgetp = function(L, idx, p) {
let t = index2addr(L, idx);
assert(t.ttistable(), "table expected");
let k = new TValue(CT.LUA_TLIGHTUSERDATA, p);
- L.stack[L.top++] = ltable.luaH_get(L, t.value, k);
+ lobject.setobj2s(L, L.top, ltable.luaH_get(L, t.value, k));
+ L.top++;
assert(L.top <= L.ci.top, "stack overflow");
return L.stack[L.top - 1].ttnov();
};
const lua_rawget = function(L, idx) {
let t = index2addr(L, idx);
-
assert(t.ttistable(t), "table expected");
-
- L.stack[L.top - 1] = ltable.luaH_get(L, t.value, L.stack[L.top - 1]);
-
+ lobject.setobj2s(L, L.top - 1, ltable.luaH_get(L, t.value, L.stack[L.top - 1]));
return L.stack[L.top - 1].ttnov();
};
@@ -552,9 +547,9 @@ const lua_getupvalue = function(L, funcindex, n) {
if (up) {
let name = up.name;
let val = up.val;
-
- L.stack[L.top++] = new TValue(val.type, val.value);
-
+ lobject.setobj2s(L, L.top, val);
+ L.top++;
+ assert(L.top <= L.ci.top, "stack overflow");
return name;
}
return null;