From ae8b95ee9c3871f506b20c74367fdc9e8cb098e2 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Mar 2017 10:23:32 +0100 Subject: lua_load will load both binary and text --- src/lapi.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/lapi.js') diff --git a/src/lapi.js b/src/lapi.js index 9a05638..36da7c6 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -2,16 +2,17 @@ const assert = require('assert'); +const ldebug = require('./ldebug.js'); const ldo = require('./ldo.js'); +const lfunc = require('./lfunc.js'); +const llex = require('./llex.js'); const lobject = require('./lobject.js'); +const lstate = require('./lstate.js'); const ltm = require('./ltm.js'); -const lfunc = require('./lfunc.js'); const lua = require('./lua.js'); const luaconf = require('./luaconf.js'); -const lstate = require('./lstate.js'); -const lvm = require('./lvm.js'); const lundump = require('./lundump.js'); -const ldebug = require('./ldebug.js'); +const lvm = require('./lvm.js'); const MAXUPVAL = lfunc.MAXUPVAL; const CT = lua.constant_types; const TS = lua.thread_status; @@ -137,7 +138,7 @@ const lua_settop = function(L, idx) { const lua_pop = function(L, n) { lua_settop(L, -n - 1); -} +}; const reverse = function(L, from, to) { for (; from < to; from++, to--) { @@ -356,7 +357,7 @@ const lua_settable = function(L, idx) { }; const lua_setfield = function(L, idx, k) { - auxsetstr(L, index2addr(L, idx), k) + auxsetstr(L, index2addr(L, idx), k); }; const lua_seti = function(L, idx, n) { @@ -514,11 +515,11 @@ const lua_rawlen = function(L, idx) { }; const lua_tointeger = function(L, idx) { - return lvm.tointeger(index2addr(L, idx)) + return lvm.tointeger(index2addr(L, idx)); }; const lua_tonumber = function(L, idx) { - return lvm.tonumber(index2addr(L, idx)) + return lvm.tonumber(index2addr(L, idx)); }; const lua_tothread = function(L, idx) { @@ -596,7 +597,7 @@ const lua_typename = function(L, t) { const lua_isnoneornil = function(L, n) { return lua_type(L, n) <= 0; -} +}; const lua_istable = function(L, idx) { return index2addr(L, idx).ttistable(); @@ -625,13 +626,14 @@ const lua_rawequal = function(L, index1, index2) { ** 'load' and 'call' functions (run Lua code) */ -const lua_load = function(L, data, chunckname) { +// TODO: reader is ignored because we don't implement ZIO +const lua_load = function(L, reader, data, chunckname, mode) { + let z = new llex.MBuffer(data); if (!chunckname) chunckname = "?"; - - let status = ldo.luaD_protectedparser(L, data, chunckname); - if (status === TS.LUA_OK) { + let status = ldo.luaD_protectedparser(L, z, chunckname, mode); + if (status === TS.LUA_OK) { /* no errors? */ let f = L.stack[L.top - 1]; /* get newly created function */ - if (f.nupvalues >= 1) { /* does it have an upvalue? */ + 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.get(lua.LUA_RIDX_GLOBALS - 1); @@ -639,7 +641,6 @@ const lua_load = function(L, data, chunckname) { f.upvals[0].u.value = gt; } } - return status; }; -- cgit v1.2.3-54-g00ecf