diff options
author | daurnimator <quae@daurnimator.com> | 2017-04-12 19:13:39 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-04-12 19:44:22 +1000 |
commit | b9d07132efcadde006a07eff7bd5ad27b4a6bd2e (patch) | |
tree | 878a48311be753508a2479b944767a7945219405 /tests | |
parent | fc08312ebf8cf01a53b4826acce0f1c3aedcdc53 (diff) | |
download | fengari-b9d07132efcadde006a07eff7bd5ad27b4a6bd2e.tar.gz fengari-b9d07132efcadde006a07eff7bd5ad27b4a6bd2e.tar.bz2 fengari-b9d07132efcadde006a07eff7bd5ad27b4a6bd2e.zip |
Try CLI input with 'return' prepended
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/manual-tests/lua-cli.js | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tests/manual-tests/lua-cli.js b/tests/manual-tests/lua-cli.js index 6c7801c..6938a8b 100755 --- a/tests/manual-tests/lua-cli.js +++ b/tests/manual-tests/lua-cli.js @@ -12,6 +12,8 @@ readlineSync.setDefaultOptions({ prompt: '> ' }); +const stdin = lua.to_luastring("=stdin"); + const L = lauxlib.luaL_newstate(); linit.luaL_openlibs(L); @@ -24,10 +26,26 @@ for (;;) { if (input.length === 0) continue; - let buffer = lua.to_luastring(input); - if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, lua.to_luastring("=stdin")) - || lapi.lua_pcall(L, 0, 0, 0)) { + let status; + { + let buffer = lua.to_luastring("return " + input); + status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin); + } + if (status !== lua.thread_status.LUA_OK) { + lapi.lua_pop(L, 1); + let buffer = lua.to_luastring(input); + if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.thread_status.LUA_OK) { + status = lua.thread_status.LUA_OK; + } + } + if (status !== lua.thread_status.LUA_OK) { lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`); + continue; + } + if (lapi.lua_pcall(L, 0, 0, 0) !== lua.thread_status.LUA_OK) { + lauxlib.lua_writestringerror(`${lapi.lua_tojsstring(L, -1)}\n`); + lapi.lua_settop(L, 0); + continue; } lapi.lua_settop(L, 0); /* remove eventual returns */ } |