aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-03 19:18:47 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-03 19:43:06 +1000
commitb575979804c25aec993e7699b2ec00265d5b70ff (patch)
tree31a9f077be70e1c3b366516a896feaf8f4b2e8c2
parent735bc392056f7c55c981b68feb941bf1cc5a8ff3 (diff)
downloadfengari-b575979804c25aec993e7699b2ec00265d5b70ff.tar.gz
fengari-b575979804c25aec993e7699b2ec00265d5b70ff.tar.bz2
fengari-b575979804c25aec993e7699b2ec00265d5b70ff.zip
src/lauxlib: Rewrite luaL_execresult
-rw-r--r--src/lauxlib.js32
-rw-r--r--src/loslib.js4
2 files changed, 21 insertions, 15 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index b020d04..c5e0d59 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -211,21 +211,27 @@ const luaL_fileresult = function(L, stat, fname, e) {
};
/* Unlike normal lua, we pass in an error object */
-const luaL_execresult = function(L, stat, e) {
- let what = lua.to_luastring("exit"); /* type of termination */
- if (e && e.status === -1) /* error? */
- return luaL_fileresult(L, 0, null, e);
- else {
- if (e && e.signal) {
- lua.lua_pushnil(L);
- lua.lua_pushliteral(L, "signal");
- } else {
- lua.lua_pushboolean(L, 1);
- lua.lua_pushliteral(L, "exit");
- }
- lua.lua_pushinteger(L, e ? e.status : 0);
+const luaL_execresult = function(L, e) {
+ let what, stat;
+ if (e === null) {
+ lua.lua_pushboolean(L, 1);
+ lua.lua_pushliteral(L, "exit");
+ lua.lua_pushinteger(L, 0);
return 3;
+ } else if (e.status) {
+ what = "exit";
+ stat = e.status;
+ } else if (e.signal) {
+ what = "signal";
+ stat = e.signal;
+ } else {
+ /* XXX: node seems to have e.errno as a string instead of a number */
+ return luaL_fileresult(L, 0, null, e);
}
+ lua.lua_pushnil(L);
+ lua.lua_pushliteral(L, what);
+ lua.lua_pushinteger(L, stat);
+ return 3;
};
const luaL_getmetatable = function(L, n) {
diff --git a/src/loslib.js b/src/loslib.js
index 6fd5247..b93071b 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -247,10 +247,10 @@ if (typeof require === "function") {
}
);
} catch (e) {
- return lauxlib.luaL_execresult(L, false, e);
+ return lauxlib.luaL_execresult(L, e);
}
- return lauxlib.luaL_execresult(L, true);
+ return lauxlib.luaL_execresult(L, null);
} else {
try {
child_process.execSync(