aboutsummaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-17 11:33:23 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-02-17 11:34:49 +0100
commita8e82fc01f2558550289f76f55c917039296ec11 (patch)
treeb226aeca2d8445ee8bcfd644477992a0635e46e0 /src/lapi.js
parent4a03542f6ebc8c6d4ed624bc0d30f5a7148a279b (diff)
downloadfengari-a8e82fc01f2558550289f76f55c917039296ec11.tar.gz
fengari-a8e82fc01f2558550289f76f55c917039296ec11.tar.bz2
fengari-a8e82fc01f2558550289f76f55c917039296ec11.zip
lua_load (bytecode only), lua_call(k)
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 976841d..6cc95b2 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -240,6 +240,24 @@ const lua_typename = function(L, t) {
** 'load' and 'call' functions (run Lua code)
*/
+const lua_load = function(L, data, chunckname) {
+ if (!chunckname) chunckname = "?";
+
+ let status = ldo.luaD_protectedparser(L, data, chunckname);
+ if (status === TS.LUA_OK) {
+ let f = L.stack[L.top - 1]; /* get newly created function */
+ 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];
+ /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
+ f.upvals[0].v = gt; // TODO: is gt on the stack ? is that upvalue opened or closed ?
+ }
+ }
+
+ return status;
+};
+
const lua_callk = function(L, nargs, nresults, ctx, k) {
assert(k === null || !(L.ci.callstatus & CIST_LUA), "cannot use continuations inside hooks");
assert(nargs + 1 < L.top - L.ci.funcOff, "not enough elements in the stack");
@@ -333,6 +351,7 @@ module.exports.lua_tointeger = lua_tointeger;
module.exports.lua_toboolean = lua_toboolean;
module.exports.lua_tolstring = lua_tolstring;
module.exports.lua_tostring = lua_tostring;
+module.exports.lua_load = lua_load;
module.exports.lua_callk = lua_callk;
module.exports.lua_call = lua_call;
module.exports.lua_pop = lua_pop; \ No newline at end of file