@@ -103,7 +103,6 @@ void Eluna::CloseLua()
103103 if (L)
104104 lua_close (L);
105105 L = NULL ;
106- stacktraceFunctionStackIndex = 0 ;
107106
108107 instanceDataRefs.clear ();
109108 continentDataRefs.clear ();
@@ -174,10 +173,6 @@ void Eluna::OpenLua()
174173 lua_pushcfunction (L, &PrecompiledLoader);
175174 lua_rawseti (L, -2 , newLoaderIndex);
176175 lua_pop (L, 2 ); // pop loaders/searchers table, pop package table
177-
178- // Leave StackTrace function on stack and save reference to it
179- lua_pushcfunction (L, &StackTrace);
180- stacktraceFunctionStackIndex = lua_gettop (L);
181176}
182177
183178void Eluna::CreateBindStores ()
@@ -370,16 +365,24 @@ bool Eluna::ExecuteCall(int params, int res)
370365 }
371366
372367 bool usetrace = sElunaConfig ->GetConfig (CONFIG_ELUNA_TRACEBACK);
373- if (usetrace && ! lua_iscfunction (L, stacktraceFunctionStackIndex) )
368+ if (usetrace)
374369 {
375- ELUNA_LOG_ERROR (" [Eluna]: Cannot execute call: registered value is %s, not a c-function." , luaL_tolstring (L, stacktraceFunctionStackIndex, NULL ));
376- ASSERT (false ); // stack probably corrupt
370+ lua_pushcfunction (L, &StackTrace);
371+ // Stack: function, [parameters], traceback
372+ lua_insert (L, base);
373+ // Stack: traceback, function, [parameters]
377374 }
378375
379376 // Objects are invalidated when event_level hits 0
380377 ++event_level;
381- int result = lua_pcall (L, params, res, usetrace ? stacktraceFunctionStackIndex : 0 );
378+ int result = lua_pcall (L, params, res, usetrace ? base : 0 );
382379 --event_level;
380+
381+ if (usetrace)
382+ {
383+ // Stack: traceback, [results or errmsg]
384+ lua_remove (L, base);
385+ }
383386 // Stack: [results or errmsg]
384387
385388 // lua_pcall returns 0 on success.
0 commit comments