diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-04-19 10:38:44 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-04-19 10:38:44 +0200 |
commit | 8966842ba72fb1eef351355ead2e8950fd87141a (patch) | |
tree | 94909de8fef3430c0f20e8c5eb88c814ce61c679 | |
parent | a02f4e93b92e7ebb7ef038ad151e51652b0ce84d (diff) | |
parent | 662381f6669f28f90a1d50c89647d265ca3804a4 (diff) | |
download | fengari-8966842ba72fb1eef351355ead2e8950fd87141a.tar.gz fengari-8966842ba72fb1eef351355ead2e8950fd87141a.tar.bz2 fengari-8966842ba72fb1eef351355ead2e8950fd87141a.zip |
Merge branch 'master' into feature/lua-tests
-rw-r--r-- | src/lauxlib.js | 8 | ||||
-rwxr-xr-x | tests/manual-tests/lua-cli.js | 99 |
2 files changed, 56 insertions, 51 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js index 064e229..3d75282 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -513,7 +513,7 @@ if (typeof require === "function") { const errfile = function(L, what, fnameindex, error) { let serr = error.message; let filename = lapi.lua_tostring(L, fnameindex).slice(1); - lapi.lua_pushstring(L, lua.to_luastring(`cannot ${lobject.jsstring(what)} ${lobject.jsstring(filename)}: ${lobject.jsstring(serr)}`)); + lapi.lua_pushstring(L, lua.to_luastring(`cannot ${what} ${lobject.jsstring(filename)}: ${serr}`)); lapi.lua_remove(L, fnameindex); return lua.thread_status.LUA_ERRFILE; }; @@ -567,18 +567,18 @@ if (typeof require === "function") { }; const luaL_loadfilex = function(L, filename, mode) { - let jsfilename = lobject.jsstring(filename); let lf = new LoadF(); let fnameindex = lapi.lua_gettop(L) + 1; /* index of filename on the stack */ if (filename === null) { lapi.lua_pushliteral(L, "=stdin"); lf.f = process.stdin.fd; } else { + let jsfilename = lobject.jsstring(filename); lapi.lua_pushliteral(L, `@${jsfilename}`); try { lf.f = fs.openSync(jsfilename, "r"); } catch (e) { - return errfile(L, lua.to_luastring("open", true), fnameindex, e); + return errfile(L, "open", fnameindex, e); } } @@ -597,7 +597,7 @@ if (typeof require === "function") { return status; } catch (err) { lapi.lua_settop(L, fnameindex); /* ignore results from 'lua_load' */ - return errfile(L, lua.to_luastring("read", true), fnameindex); + return errfile(L, "read", fnameindex, err); } }; diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js index 3a3b386..f11e833 100755 --- a/tests/manual-tests/lua-cli.js +++ b/tests/manual-tests/lua-cli.js @@ -42,11 +42,11 @@ const dostring = function(L, s, name) { }; const dolibrary = function(L, name) { - lapi.lua_getglobal(L, "require"); + lapi.lua_getglobal(L, lua.to_luastring("require")); lapi.lua_pushliteral(L, name); let status = docall(L, 1, 1); /* call 'require(name)' */ if (status === lua.thread_status.LUA_OK) - lapi.lua_setglobal(L, name); /* global[name] = require return */ + lapi.lua_setglobal(L, lua.to_luastring(name)); /* global[name] = require return */ return report(L, status); }; @@ -79,55 +79,58 @@ let has_i = false; let has_v = false; let has_e = false; -for (let i = 2; i<process.argv.length; i++) { - script = i; - if (process.argv[i][0] != "-") { - break; - } - switch(process.argv[i][1]) { - case '-': - if (process.argv[i][2]) { - print_usage(process.argv[script]); - return process.exit(1); - } - script = i + 1; - /* falls through */ - case void 0: /* script name is '-' */ - i = process.argv.length; - break; - case 'E': - has_E = true; - break; - case 'i': - has_i = true; - /* (-i implies -v) */ - /* falls through */ - case 'v': - if (process.argv[i].length > 2) { - /* invalid option */ - print_usage(process.argv[script]); - return process.exit(1); +(function() { + let i; + for (i = 2; i<process.argv.length; i++) { + script = i; + if (process.argv[i][0] != "-") { + return; } - has_v = true; - break; - case 'e': - has_e = true; - /* falls through */ - case 'l': /* both options need an argument */ - if (process.argv[i].length < 2) { /* no concatenated argument? */ - i++; /* try next 'process.argv' */ - if (process.argv.length <= i || process.argv[i][0] === '-') { - /* no next argument or it is another option */ + switch(process.argv[i][1]) { + case '-': + if (process.argv[i][2]) { + print_usage(process.argv[script]); + return process.exit(1); + } + script = i + 1; + return; + case void 0: /* script name is '-' */ + return; + case 'E': + has_E = true; + break; + case 'i': + has_i = true; + /* (-i implies -v) */ + /* falls through */ + case 'v': + if (process.argv[i].length > 2) { + /* invalid option */ print_usage(process.argv[script]); return process.exit(1); } + has_v = true; + break; + case 'e': + has_e = true; + /* falls through */ + case 'l': /* both options need an argument */ + if (process.argv[i].length < 3) { /* no concatenated argument? */ + i++; /* try next 'process.argv' */ + if (process.argv.length <= i || process.argv[i][0] === '-') { + /* no next argument or it is another option */ + print_usage(process.argv[script]); + return process.exit(1); + } + } + break; + default: /* invalid option */ + print_usage(process.argv[script]); + return process.exit(1); } - break; - default: /* invalid option */ - print_usage(process.argv[script]); - return process.exit(1); } -} + script = i; +})(); if (has_v) console.log(lua.FENGARI_COPYRIGHT); @@ -205,8 +208,10 @@ const handle_script = function(L, argv) { let fname = argv[0]; let status; if (fname === "-" && argv[-1] !== "--") - fname = void 0; /* stdin */ - status = lauxlib.luaL_loadfile(L, lua.to_luastring(fname)); + fname = null; /* stdin */ + else + fname = lua.to_luastring(fname); + status = lauxlib.luaL_loadfile(L, fname); if (status === lua.thread_status.LUA_OK) { let n = pushargs(L); /* push arguments to script */ status = docall(L, n, lua.LUA_MULTRET); |