summaryrefslogtreecommitdiffstats
path: root/src/Bindings/LuaState.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-02-11 08:52:14 +0100
committermadmaxoft <github@xoft.cz>2014-02-11 08:52:14 +0100
commitb41bb3bb44bbc098622e45e17ed3adf34eadf2aa (patch)
treee77fe8ae79234d7cf7773c1cb77ba84e8f435328 /src/Bindings/LuaState.cpp
parentMerge branch 'master' into ChunkStay (diff)
downloadcuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar.gz
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar.bz2
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar.lz
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar.xz
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.tar.zst
cuberite-b41bb3bb44bbc098622e45e17ed3adf34eadf2aa.zip
Diffstat (limited to 'src/Bindings/LuaState.cpp')
-rw-r--r--src/Bindings/LuaState.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp
index 8f2a70a60..24e64d9b2 100644
--- a/src/Bindings/LuaState.cpp
+++ b/src/Bindings/LuaState.cpp
@@ -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);