diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-05-09 11:36:14 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-05-09 11:36:14 +0200 |
commit | 697ef457e1b0eabd3aa9fb2332a5d04478b39603 (patch) | |
tree | 4d93ec7e3d1cc698a5c54de9785d688bf510ed15 /src/lbaselib.js | |
parent | 3e439ed653093e6e124a4997f64053164f1043b8 (diff) | |
download | fengari-697ef457e1b0eabd3aa9fb2332a5d04478b39603.tar.gz fengari-697ef457e1b0eabd3aa9fb2332a5d04478b39603.tar.bz2 fengari-697ef457e1b0eabd3aa9fb2332a5d04478b39603.zip |
Webpack (single bundle for now)
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r-- | src/lbaselib.js | 59 |
1 files changed, 27 insertions, 32 deletions
diff --git a/src/lbaselib.js b/src/lbaselib.js index d1d930a..8f0827e 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -331,38 +331,33 @@ const base_funcs = { }; // Only with Node -if (typeof require === "function") { - - let fs = false; - try { - fs = require('fs'); - } catch (e) {} - - if (fs) { - const luaB_loadfile = function(L) { - let fname = lauxlib.luaL_optstring(L, 1, null); - let mode = lauxlib.luaL_optstring(L, 2, null); - let env = !lua.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); - }; - - const dofilecont = function(L, d1, d2) { - return lua.lua_gettop(L) - 1; - }; - - const luaB_dofile = function(L) { - let fname = lauxlib.luaL_optstring(L, 1, null); - lua.lua_settop(L, 1); - if (lauxlib.luaL_loadfile(L, fname) !== lua.LUA_OK) - return lua.lua_error(L); - lua.lua_callk(L, 0, lua.LUA_MULTRET, 0, dofilecont); - return dofilecont(L, 0, 0); - }; - - base_funcs.loadfile = luaB_loadfile; - base_funcs.dofile = luaB_dofile; - } +if (!WEB) { + + const fs = require('fs'); + + const luaB_loadfile = function(L) { + let fname = lauxlib.luaL_optstring(L, 1, null); + let mode = lauxlib.luaL_optstring(L, 2, null); + let env = !lua.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); + }; + + const dofilecont = function(L, d1, d2) { + return lua.lua_gettop(L) - 1; + }; + + const luaB_dofile = function(L) { + let fname = lauxlib.luaL_optstring(L, 1, null); + lua.lua_settop(L, 1); + if (lauxlib.luaL_loadfile(L, fname) !== lua.LUA_OK) + return lua.lua_error(L); + lua.lua_callk(L, 0, lua.LUA_MULTRET, 0, dofilecont); + return dofilecont(L, 0, 0); + }; + + base_funcs.loadfile = luaB_loadfile; + base_funcs.dofile = luaB_dofile; } |