Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from ElunaLuaEngine:master #93

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions LuaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void Eluna::CloseLua()
if (L)
lua_close(L);
L = NULL;
stacktraceFunctionStackIndex = 0;

instanceDataRefs.clear();
continentDataRefs.clear();
Expand Down Expand Up @@ -174,10 +173,6 @@ void Eluna::OpenLua()
lua_pushcfunction(L, &PrecompiledLoader);
lua_rawseti(L, -2, newLoaderIndex);
lua_pop(L, 2); // pop loaders/searchers table, pop package table

// Leave StackTrace function on stack and save reference to it
lua_pushcfunction(L, &StackTrace);
stacktraceFunctionStackIndex = lua_gettop(L);
}

void Eluna::CreateBindStores()
Expand Down Expand Up @@ -370,16 +365,24 @@ bool Eluna::ExecuteCall(int params, int res)
}

bool usetrace = sElunaConfig->GetConfig(CONFIG_ELUNA_TRACEBACK);
if (usetrace && !lua_iscfunction(L, stacktraceFunctionStackIndex))
if (usetrace)
{
ELUNA_LOG_ERROR("[Eluna]: Cannot execute call: registered value is %s, not a c-function.", luaL_tolstring(L, stacktraceFunctionStackIndex, NULL));
ASSERT(false); // stack probably corrupt
lua_pushcfunction(L, &StackTrace);
// Stack: function, [parameters], traceback
lua_insert(L, base);
// Stack: traceback, function, [parameters]
}

// Objects are invalidated when event_level hits 0
++event_level;
int result = lua_pcall(L, params, res, usetrace ? stacktraceFunctionStackIndex : 0);
int result = lua_pcall(L, params, res, usetrace ? base : 0);
--event_level;

if (usetrace)
{
// Stack: traceback, [results or errmsg]
lua_remove(L, base);
}
// Stack: [results or errmsg]

// lua_pcall returns 0 on success.
Expand Down
4 changes: 0 additions & 4 deletions LuaEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ class ELUNA_GAME_API Eluna
// Whether or not Eluna is in compatibility mode. Used in some method wrappers.
bool compatibilityMode;

// Index of the Eluna::StackTrace function pushed to the lua state stack when lua is opened
// We store the function to stack on lua open because it cannot be a pseudo-index (must be on stack) and we want access it on every call
int stacktraceFunctionStackIndex = 0;

// Map from instance ID -> Lua table ref
std::unordered_map<uint32, int> instanceDataRefs;
// Map from map ID -> Lua table ref
Expand Down
Loading