diff options
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lapi.js b/src/lapi.js index 72ff554..32a9873 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -182,6 +182,11 @@ const lua_insert = function(L, idx) { lua_rotate(L, idx, 1); }; +const lua_replace = function(L, idx) { + lua_copy(L, -1, idx); + lua_pop(L, 1); +}; + /* ** push functions (JS -> stack) */ @@ -424,6 +429,19 @@ const lua_createtable = function(L, narray, nrec) { assert(L.top <= L.ci.top, "stack overflow"); }; +const lua_setupvalue = function(L, funcindex, n) { + let fi = index2addr(L, funcindex); + assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack"); + let aux = aux_upvalue(fi, n); + let name = aux.name; + let val = aux.val; + if (name) { + L.top--; + setobj(L, val, L.top); + } + return name; +}; + const lua_newtable = function(L) { lua_createtable(L, 0, 0); }; @@ -595,6 +613,14 @@ const lua_typename = function(L, t) { return ltm.ttypename(t); }; +const lua_isnil = function(L, n) { + return lua_type(L, n) === CT.LUA_TNIL; +}; + +const lua_isnone = function(L, n) { + return lua_type(L, n) === CT.LUA_TNONE; +}; + const lua_isnoneornil = function(L, n) { return lua_type(L, n) <= 0; }; @@ -798,6 +824,8 @@ module.exports.lua_gettable = lua_gettable; module.exports.lua_gettop = lua_gettop; module.exports.lua_insert = lua_insert; module.exports.lua_isinteger = lua_isinteger; +module.exports.lua_isnil = lua_isnil; +module.exports.lua_isnone = lua_isnone; module.exports.lua_isnoneornil = lua_isnoneornil; module.exports.lua_isnumber = lua_isnumber; module.exports.lua_isstring = lua_isstring; @@ -830,6 +858,7 @@ module.exports.lua_rawgeti = lua_rawgeti; module.exports.lua_rawlen = lua_rawlen; module.exports.lua_rawset = lua_rawset; module.exports.lua_remove = lua_remove; +module.exports.lua_replace = lua_replace; module.exports.lua_rotate = lua_rotate; module.exports.lua_setfield = lua_setfield; module.exports.lua_setglobal = lua_setglobal; |