summaryrefslogtreecommitdiff
path: root/src/loslib.js
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-04-28 14:42:41 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-04-28 14:42:41 +0200
commit354d659f577fc27969784400c8c1e6090756da7b (patch)
tree4aa17f23121794bc8b855e2ed0bf85951281b37e /src/loslib.js
parentcebad06a3429e28cb5e0c247c707bb5eb51943d8 (diff)
downloadfengari-354d659f577fc27969784400c8c1e6090756da7b.tar.gz
fengari-354d659f577fc27969784400c8c1e6090756da7b.tar.bz2
fengari-354d659f577fc27969784400c8c1e6090756da7b.zip
os.exit
Diffstat (limited to 'src/loslib.js')
-rw-r--r--src/loslib.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/loslib.js b/src/loslib.js
index 3892d35..a715aec 100644
--- a/src/loslib.js
+++ b/src/loslib.js
@@ -66,6 +66,23 @@ const syslib = {
"time": os_time
};
+// Only with Node
+if (process && process.exit) {
+ const os_exit = function(L) {
+ let status;
+ if (lua.lua_isboolean(L, 1))
+ status = (lua.lua_toboolean(L, 1) ? 0 : 1);
+ else
+ status = lauxlib.luaL_optinteger(L, 1, 0);
+ if (lua.lua_toboolean(L, 2))
+ lua.lua_close(L);
+ if (L) process.exit(status); /* 'if' to avoid warnings for unreachable 'return' */
+ return 0;
+ };
+
+ syslib.exit = os_exit;
+}
+
const luaopen_os = function(L) {
lauxlib.luaL_newlib(L, syslib);
return 1;