From 78b48979b8dbd367043c39fb21007ab4f54cd0a4 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Fri, 17 Feb 2017 14:13:10 +0100 Subject: lua_settable, lua_gettable --- src/lapi.js | 18 +++++++++++++++++- src/lvm.js | 4 +++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lapi.js b/src/lapi.js index 089f138..705fec4 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -210,6 +210,14 @@ const lua_setglobal = function(L, name) { auxsetstr(L, L.l_G.l_registry.value.array[lua.LUA_RIDX_GLOBALS], name); }; +const lua_settable = function(L, idx) { + assert(2 < L.top - L.ci.funcOff, "not enough elements in the stack"); + + let t = index2addr(L, idx); + lvm.settable(L, t, L.stack[L.top - 2], L.stack[L.top - 1]); + L.top -= 2; +}; + /* ** get functions (Lua -> stack) @@ -230,6 +238,12 @@ const lua_newtable = function(L) { lua_createtable(L, 0, 0); }; +const lua_gettable = function(L, idx) { + let t = index2addr(L, idx); + lvm.gettable(L, t, L.stack[L.top - 1], L.top - 1); + return L.stack[L.top - 1].ttnov(); +}; + /* ** access functions (stack -> JS) @@ -401,4 +415,6 @@ module.exports.lua_pop = lua_pop; module.exports.lua_setglobal = lua_setglobal; module.exports.lua_istable = lua_istable; module.exports.lua_createtable = lua_createtable; -module.exports.lua_newtable = lua_newtable; \ No newline at end of file +module.exports.lua_newtable = lua_newtable; +module.exports.lua_settable = lua_settable; +module.exports.lua_gettable = lua_gettable; \ No newline at end of file diff --git a/src/lvm.js b/src/lvm.js index 4f52678..a75e305 100644 --- a/src/lvm.js +++ b/src/lvm.js @@ -1034,4 +1034,6 @@ module.exports.LEintfloat = LEintfloat; module.exports.LTintfloat = LTintfloat; module.exports.l_strcmp = l_strcmp; module.exports.luaV_objlen = luaV_objlen; -module.exports.luaV_finishset = luaV_finishset; \ No newline at end of file +module.exports.luaV_finishset = luaV_finishset; +module.exports.gettable = gettable; +module.exports.settable = settable; \ No newline at end of file -- cgit v1.2.3-70-g09d2