aboutsummaryrefslogtreecommitdiff
path: root/src/lapi.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 10:23:32 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-01 10:56:03 +0100
commitae8b95ee9c3871f506b20c74367fdc9e8cb098e2 (patch)
tree6348ab52aad93905af66196f5d071628ac60adb5 /src/lapi.js
parent74dda64eab7951da520dc451a1f3bbb8c7d62706 (diff)
downloadfengari-ae8b95ee9c3871f506b20c74367fdc9e8cb098e2.tar.gz
fengari-ae8b95ee9c3871f506b20c74367fdc9e8cb098e2.tar.bz2
fengari-ae8b95ee9c3871f506b20c74367fdc9e8cb098e2.zip
lua_load will load both binary and text
Diffstat (limited to 'src/lapi.js')
-rw-r--r--src/lapi.js31
1 files changed, 16 insertions, 15 deletions
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;
};