]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Support os.exit(status|true|false [,close]) (from Lua 5.2).
authorMike Pall <mike>
Mon, 22 Nov 2010 21:39:06 +0000 (22:39 +0100)
committerMike Pall <mike>
Mon, 22 Nov 2010 21:39:06 +0000 (22:39 +0100)
src/lib_os.c

index 690bffe8e5d761e3a3ebfc982d820ab7e858357a..a62fd3b451169fb45d770276618a43ff17b7c65d 100644 (file)
@@ -92,8 +92,15 @@ LJLIB_CF(os_getenv)
 
 LJLIB_CF(os_exit)
 {
-  exit(lj_lib_optint(L, 1, EXIT_SUCCESS));
-  return 0;  /* to avoid warnings */
+  int status;
+  if (L->base < L->top && tvisbool(L->base))
+    status = boolV(L->base) ? EXIT_SUCCESS : EXIT_FAILURE;
+  else
+    status = lj_lib_optint(L, 1, EXIT_SUCCESS);
+  if (L->base+1 < L->top && tvistruecond(L->base+1))
+    lua_close(L);
+  exit(status);
+  return 0;  /* Unreachable. */
 }
 
 LJLIB_CF(os_clock)