Fixed nested plugin function calls.
This commit is contained in:
parent
8a8997cc38
commit
b41bb3bb44
@ -735,17 +735,20 @@ bool cLuaState::CallFunction(int a_NumResults)
|
||||
ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 1)); // The function to call
|
||||
ASSERT(lua_isfunction(m_LuaState, -m_NumCurrentFunctionArgs - 2)); // The error handler
|
||||
|
||||
int s = lua_pcall(m_LuaState, m_NumCurrentFunctionArgs, a_NumResults, -m_NumCurrentFunctionArgs - 2);
|
||||
// Save the current "stack" state and reset, in case the callback calls another function:
|
||||
AString CurrentFunctionName;
|
||||
std::swap(m_CurrentFunctionName, CurrentFunctionName);
|
||||
int NumArgs = m_NumCurrentFunctionArgs;
|
||||
m_NumCurrentFunctionArgs = -1;
|
||||
|
||||
// Call the function:
|
||||
int s = lua_pcall(m_LuaState, NumArgs, a_NumResults, -NumArgs - 2);
|
||||
if (s != 0)
|
||||
{
|
||||
// The error has already been printed together with the stacktrace
|
||||
LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), m_CurrentFunctionName.c_str());
|
||||
m_NumCurrentFunctionArgs = -1;
|
||||
m_CurrentFunctionName.clear();
|
||||
LOGWARNING("Error in %s calling function %s()", m_SubsystemName.c_str(), CurrentFunctionName.c_str());
|
||||
return false;
|
||||
}
|
||||
m_NumCurrentFunctionArgs = -1;
|
||||
m_CurrentFunctionName.clear();
|
||||
|
||||
// Remove the error handler from the stack:
|
||||
lua_remove(m_LuaState, -a_NumResults - 1);
|
||||
|
Loading…
Reference in New Issue
Block a user