Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
luafiveq/patches/os-exit.patch
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
33 lines (26 sloc)
1.05 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Make os.exit close lua_State | |
| Author: dubiousjim@gmail.com | |
| Derived from: Lua 5.2 sources | |
| Updated: 17 May 2012 | |
| If an optional second argument is true, calls lua_close before exiting, so | |
| finalizers will be run. The Lua interpreter already calls lua_close when | |
| exiting normally, but other applications embedding Lua may not; and you may | |
| want this behavior when using os.exit (to force non-zero exit statuses). | |
| This behavior cannot be provided by a library, but only by patching the Lua | |
| source and rebuilding. | |
| diff -urN lua-5.1.5.orig/src/loslib.c lua-5.1.5/src/loslib.c | |
| --- lua-5.1.5.orig/src/loslib.c 2008-01-18 11:38:18.000000000 -0500 | |
| +++ lua-5.1.5/src/loslib.c 2012-05-17 12:06:50.940848174 -0400 | |
| @@ -214,7 +214,14 @@ | |
| static int os_exit (lua_State *L) { | |
| - exit(luaL_optint(L, 1, EXIT_SUCCESS)); | |
| + int status; | |
| + if (lua_isboolean(L, 1)) | |
| + status = (lua_toboolean(L, 1) ? EXIT_SUCCESS : EXIT_FAILURE); | |
| + else | |
| + status = luaL_optint(L, 1, EXIT_SUCCESS); | |
| + if (lua_toboolean(L, 2)) | |
| + lua_close(L); | |
| + exit(status); | |
| } | |
| static const luaL_Reg syslib[] = { |