summaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 625608b..e9f15c2 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -293,7 +293,7 @@ const auxsetstr = function(L, t, k) {
};
const lua_setglobal = function(L, name) {
- auxsetstr(L, L.l_G.l_registry.value.array[lua.LUA_RIDX_GLOBALS - 1], name);
+ auxsetstr(L, L.l_G.l_registry.value.get(lua.LUA_RIDX_GLOBALS - 1), name);
};
const lua_setmetatable = function(L, objindex) {
@@ -390,9 +390,6 @@ const lua_createtable = function(L, narray, nrec) {
L.stack[L.top++] = t;
assert(L.top <= L.ci.top, "stack overflow");
-
- if (narray > 0)
- t.value.array = new Array(narray);
};
const lua_newtable = function(L) {
@@ -447,7 +444,7 @@ const lua_geti = function(L, idx, n) {
};
const lua_getglobal = function(L, name) {
- return auxgetstr(L, L.l_G.l_registry.value.array[lua.LUA_RIDX_GLOBALS - 1], name);
+ return auxgetstr(L, L.l_G.l_registry.value.get(lua.LUA_RIDX_GLOBALS - 1), name);
};
/*
@@ -558,7 +555,7 @@ const lua_load = function(L, data, chunckname) {
if (f.nupvalues >= 1) { /* does it have an upvalue? */
/* get global table from registry */
let reg = L.l_G.l_registry;
- let gt = reg.value.array[lua.LUA_RIDX_GLOBALS - 1];
+ let gt = reg.value.get(lua.LUA_RIDX_GLOBALS - 1);
/* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
f.upvals[0].u.value = gt;
}
@@ -654,7 +651,16 @@ const lua_error = function(L) {
};
const lua_next = function(L, idx) {
-
+ let t = index2addr(L, idx);
+ assert(t.ttistable(), "table expected");
+ let more = t.luaH_next(L, L.top - 1);
+ if (more) {
+ L.top++;
+ assert(L.top <= L.ci.top, "stack overflow");
+ } else
+ L.top--;
+
+ return more;
};
const lua_concat = function(L, n) {
@@ -740,4 +746,5 @@ module.exports.lua_gc = lua_gc;
module.exports.lua_getallocf = lua_getallocf;
module.exports.lua_getextraspace = lua_getextraspace;
module.exports.lua_stringtonumber = lua_stringtonumber;
-module.exports.lua_copy = lua_copy; \ No newline at end of file
+module.exports.lua_copy = lua_copy;
+module.exports.lua_next = lua_next; \ No newline at end of file