diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-08-09 10:35:45 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-08-10 08:48:24 +0200 |
commit | 10ce504e5defe8411f089c796dea370e9e14d014 (patch) | |
tree | 85811930305b8945b173340513497361fd5b1261 /src/loadlib.js | |
parent | f90446e631b244856e5f495d89491ee2356ecbef (diff) | |
download | fengari-10ce504e5defe8411f089c796dea370e9e14d014.tar.gz fengari-10ce504e5defe8411f089c796dea370e9e14d014.tar.bz2 fengari-10ce504e5defe8411f089c796dea370e9e14d014.zip |
luaL_loadfile will load via xhr in the browser
Diffstat (limited to 'src/loadlib.js')
-rw-r--r-- | src/loadlib.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/loadlib.js b/src/loadlib.js index e448381..9400bb0 100644 --- a/src/loadlib.js +++ b/src/loadlib.js @@ -34,7 +34,7 @@ const AUXMARK = [1]; ** Returns the library; in case of error, returns NULL plus an ** error string in the stack. */ -const lsys_load = function(L, path) { +let lsys_load = function(L, path) { try { path = lua.to_jsstring(path); @@ -65,6 +65,22 @@ const lsys_sym = function(L, lib, sym) { } }; +if (WEB) { + lsys_load = function(L, path) { + let xhr = new XMLHttpRequest(); + xhr.open("GET", lua.to_jsstring(path), false); + xhr.send(); + /* TODO: subresource integrity check? */ + + if (xhr.status === 200) { + return eval(xhr.response); + } else { + lua.lua_pushstring(L, lua.to_luastring(`${xhr.status}: ${xhr.statusText}`)); + return null; + } + }; +} + /* ** return registry.LUA_NOENV as a boolean */ |