Skip to content

Commit de1b74b

Browse files
#3119 don't skip atexit() functions; add demo script
1 parent bc97238 commit de1b74b

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

indra/llcommon/lua_function.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -822,34 +822,34 @@ LuaState::~LuaState()
822822
<< len << " entries" << LL_ENDL;
823823

824824
// TODO: 'debug' global shouldn't be overwritten and should be accessible at this stage
825-
if (push_debug_traceback())
825+
bool debug_traceback = push_debug_traceback();
826+
// if debug_traceback is true, stack now contains atexit, /debug.traceback()/
827+
// otherwise just atexit
828+
for (int i(len); i >= 1; --i)
826829
{
827-
// stack now contains atexit, debug.traceback()
828-
for (int i(len); i >= 1; --i)
830+
lua_pushinteger(mState, i);
831+
// stack contains Registry.atexit, /debug.traceback()/, i
832+
lua_gettable(mState, debug_traceback ? -3 : -2);
833+
// stack contains Registry.atexit, /debug.traceback()/, atexit[i]
834+
// Call atexit[i](), no args, no return values.
835+
// Use lua_pcall() because errors in any one atexit() function
836+
// shouldn't cancel the rest of them. Pass debug.traceback() as
837+
// the error handler function.
838+
LL_DEBUGS("Lua") << LLCoros::getName() << ": calling atexit(" << i << ")" << LL_ENDL;
839+
if (lua_pcall(mState, 0, 0, debug_traceback ? -2 : 0) != LUA_OK)
829840
{
830-
lua_pushinteger(mState, i);
831-
// stack contains Registry.atexit, debug.traceback(), i
832-
lua_gettable(mState, -3);
833-
// stack contains Registry.atexit, debug.traceback(), atexit[i]
834-
// Call atexit[i](), no args, no return values.
835-
// Use lua_pcall() because errors in any one atexit() function
836-
// shouldn't cancel the rest of them. Pass debug.traceback() as
837-
// the error handler function.
838-
LL_DEBUGS("Lua") << LLCoros::getName() << ": calling atexit(" << i << ")" << LL_ENDL;
839-
if (lua_pcall(mState, 0, 0, -2) != LUA_OK)
840-
{
841-
auto error{ lua_tostdstring(mState, -1) };
842-
LL_WARNS("Lua") << LLCoros::getName() << ": atexit(" << i << ") error: " << error << LL_ENDL;
843-
// pop error message
844-
lua_pop(mState, 1);
845-
}
846-
LL_DEBUGS("Lua") << LLCoros::getName() << ": atexit(" << i << ") done" << LL_ENDL;
847-
// lua_pcall() has already popped atexit[i]:
848-
// stack contains atexit, debug.traceback()
841+
auto error{ lua_tostdstring(mState, -1) };
842+
LL_WARNS("Lua") << LLCoros::getName() << ": atexit(" << i << ") error: " << error << LL_ENDL;
843+
// pop error message
844+
lua_pop(mState, 1);
849845
}
850-
// pop debug.traceback()
851-
lua_pop(mState, 1);
846+
LL_DEBUGS("Lua") << LLCoros::getName() << ": atexit(" << i << ") done" << LL_ENDL;
847+
// lua_pcall() has already popped atexit[i]:
848+
// stack contains atexit, debug.traceback()
852849
}
850+
// pop debug.traceback()
851+
if(debug_traceback)
852+
lua_pop(mState, 1);
853853
}
854854
// pop Registry.atexit (either table or nil)
855855
lua_pop(mState, 1);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local LLDebugSettings = require 'LLDebugSettings'
2+
local SETTING_NAME = '360CaptureCameraFOV'
3+
LL.atexit(function() LL.print_info('Finished') end)
4+
5+
LL.print_info('Updating ' .. SETTING_NAME)
6+
LLDebugSettings.set(SETTING_NAME, 100)
7+
8+
debug = LLDebugSettings.get(SETTING_NAME)
9+
LL.print_info(debug)
10+

0 commit comments

Comments
 (0)