Browse Source

Support os.exit(status|true|false [,close]) (from Lua 5.2).

Mike Pall 15 years ago
parent
commit
7338456796
1 changed files with 9 additions and 2 deletions
  1. 9 2
      src/lib_os.c

+ 9 - 2
src/lib_os.c

@@ -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)