Skip to content

Commit 9e6039e

Browse files
#3119 code clean up
1 parent de1b74b commit 9e6039e

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

indra/llcommon/lua_function.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ int lua_metaipair(lua_State* L)
764764

765765
} // anonymous namespace
766766

767-
bool LuaState::push_debug_traceback()
767+
int LuaState::push_debug_traceback()
768768
{
769769
// Push debug.traceback() onto the stack as lua_pcall()'s error
770770
// handler function. On error, lua_pcall() calls the specified error
@@ -778,18 +778,18 @@ bool LuaState::push_debug_traceback()
778778
{
779779
lua_pop(mState, 1);
780780
LL_WARNS("Lua") << "'debug' table not found" << LL_ENDL;
781-
return false;
781+
return 0;
782782
}
783783
lua_getfield(mState, -1, "traceback");
784784
if (!lua_isfunction(mState, -1))
785785
{
786786
lua_pop(mState, 2);
787787
LL_WARNS("Lua") << "'traceback' func not found" << LL_ENDL;
788-
return false;
788+
return 0;
789789
}
790790
// ditch "debug"
791791
lua_remove(mState, -2);
792-
return true;
792+
return lua_gettop(mState);
793793
}
794794

795795
LuaState::~LuaState()
@@ -812,6 +812,8 @@ LuaState::~LuaState()
812812
// stack contains Registry.atexit
813813
if (lua_istable(mState, -1))
814814
{
815+
int atexit = lua_gettop(mState);
816+
815817
// We happen to know that Registry.atexit is built by appending array
816818
// entries using table.insert(). That's important because it means
817819
// there are no holes, and therefore lua_objlen() should be correct.
@@ -822,21 +824,21 @@ LuaState::~LuaState()
822824
<< len << " entries" << LL_ENDL;
823825

824826
// TODO: 'debug' global shouldn't be overwritten and should be accessible at this stage
825-
bool debug_traceback = push_debug_traceback();
827+
S32 debug_traceback_idx = push_debug_traceback();
826828
// if debug_traceback is true, stack now contains atexit, /debug.traceback()/
827829
// otherwise just atexit
828830
for (int i(len); i >= 1; --i)
829831
{
830832
lua_pushinteger(mState, i);
831833
// stack contains Registry.atexit, /debug.traceback()/, i
832-
lua_gettable(mState, debug_traceback ? -3 : -2);
834+
lua_gettable(mState, atexit);
833835
// stack contains Registry.atexit, /debug.traceback()/, atexit[i]
834836
// Call atexit[i](), no args, no return values.
835837
// Use lua_pcall() because errors in any one atexit() function
836838
// shouldn't cancel the rest of them. Pass debug.traceback() as
837839
// the error handler function.
838840
LL_DEBUGS("Lua") << LLCoros::getName() << ": calling atexit(" << i << ")" << LL_ENDL;
839-
if (lua_pcall(mState, 0, 0, debug_traceback ? -2 : 0) != LUA_OK)
841+
if (lua_pcall(mState, 0, 0, debug_traceback_idx) != LUA_OK)
840842
{
841843
auto error{ lua_tostdstring(mState, -1) };
842844
LL_WARNS("Lua") << LLCoros::getName() << ": atexit(" << i << ") error: " << error << LL_ENDL;
@@ -848,8 +850,8 @@ LuaState::~LuaState()
848850
// stack contains atexit, debug.traceback()
849851
}
850852
// pop debug.traceback()
851-
if(debug_traceback)
852-
lua_pop(mState, 1);
853+
if (debug_traceback_idx)
854+
lua_remove(mState, debug_traceback_idx);
853855
}
854856
// pop Registry.atexit (either table or nil)
855857
lua_pop(mState, 1);

indra/llcommon/lua_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class LuaState
122122
void set_interrupts_counter(S32 counter);
123123
void check_interrupts_counter();
124124

125-
bool push_debug_traceback();
125+
int push_debug_traceback();
126126

127127
private:
128128
/*---------------------------- feature flag ----------------------------*/

indra/newview/scripts/lua/test_debugsettings.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ LL.atexit(function() LL.print_info('Finished') end)
44

55
LL.print_info('Updating ' .. SETTING_NAME)
66
LLDebugSettings.set(SETTING_NAME, 100)
7-
7+
-- 'inadvertently' using Luau library as variable name to hide it
88
debug = LLDebugSettings.get(SETTING_NAME)
99
LL.print_info(debug)
10-

0 commit comments

Comments
 (0)