summaryrefslogtreecommitdiff
path: root/src/lbaselib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-21 15:29:53 +0100
committerBenoit Giannangeli <benoit.giannangeli@boursorama.fr>2017-03-23 08:28:07 +0100
commit9e08fa3a4b9f8848bb4eac3e745079282099a3d8 (patch)
tree64be88a45075fe93bbd8c03c3244d3a83fad7491 /src/lbaselib.js
parentc4b23126f0cb803ec944c5d7877bbf669f582374 (diff)
downloadfengari-9e08fa3a4b9f8848bb4eac3e745079282099a3d8.tar.gz
fengari-9e08fa3a4b9f8848bb4eac3e745079282099a3d8.tar.bz2
fengari-9e08fa3a4b9f8848bb4eac3e745079282099a3d8.zip
loadfile
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r--src/lbaselib.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js
index 0b5c2f7..604a005 100644
--- a/src/lbaselib.js
+++ b/src/lbaselib.js
@@ -332,6 +332,36 @@ const base_funcs = {
"xpcall": luaB_xpcall
};
+// Only with Node
+if (typeof window === "undefined") {
+
+ const load_aux = function(L, status, envidx) {
+ if (status === TS.LUA_OK) {
+ if (envidx !== 0) { /* 'env' parameter? */
+ lapi.lua_pushvalue(L, envidx); /* environment for loaded function */
+ if (!lapi.lua_setupvalue(L, -2, 1)) /* set it as 1st upvalue */
+ lapi.lua_pop(L, 1); /* remove 'env' if not used by previous call */
+ }
+ return 1;
+ } else { /* error (message is on top of the stack) */
+ lapi.lua_pushnil(L);
+ lapi.lua_insert(L, -2); /* put before error message */
+ return 2; /* return nil plus error message */
+ }
+ };
+
+ const luaB_loadfile = function(L) {
+ let fname = lauxlib.luaL_optstring(L, 1, null);
+ let mode = lauxlib.luaL_optstring(L, 2, null);
+ let env = !lapi.lua_isnone(L, 3) ? 3 : 0; /* 'env' index or 0 if no 'env' */
+ let status = lauxlib.luaL_loadfilex(L, fname, mode);
+ return load_aux(L, status, env);
+ };
+
+ base_funcs.loadfile = luaB_loadfile;
+
+}
+
const luaopen_base = function(L) {
/* open lib into global table */
lapi.lua_pushglobaltable(L);