Fixed inter-plugin calls.
When an inter-plugin call failed due to function not found, the server would maul the LuaState and "yield". Fixes #1959.
This commit is contained in:
parent
ceac39c4cd
commit
fee690a3d1
|
@ -54,7 +54,7 @@ function Initialize(a_Plugin)
|
||||||
-- TestBlockAreas()
|
-- TestBlockAreas()
|
||||||
-- TestSQLiteBindings()
|
-- TestSQLiteBindings()
|
||||||
-- TestExpatBindings()
|
-- TestExpatBindings()
|
||||||
-- TestPluginCalls()
|
TestPluginCalls()
|
||||||
|
|
||||||
TestBlockAreasString()
|
TestBlockAreasString()
|
||||||
TestStringBase64()
|
TestStringBase64()
|
||||||
|
@ -157,26 +157,18 @@ function TestPluginCalls()
|
||||||
-- The Split parameter should be a table, but it is not used in that function anyway,
|
-- The Split parameter should be a table, but it is not used in that function anyway,
|
||||||
-- so we can get away with passing nil to it.
|
-- so we can get away with passing nil to it.
|
||||||
|
|
||||||
-- Use the old, deprecated and unsafe method:
|
LOG("Debuggers: Calling NoSuchPlugin.FnName()...")
|
||||||
local Core = cPluginManager:Get():GetPlugin("Core")
|
cPluginManager:CallPlugin("NoSuchPlugin", "FnName", "SomeParam")
|
||||||
if (Core ~= nil) then
|
LOG("Debuggers: Calling Core.NoSuchFunction()...")
|
||||||
LOGINFO("Calling Core::ReturnColorFromChar() the old-fashioned way...")
|
cPluginManager:CallPlugin("Core", "NoSuchFunction", "SomeParam")
|
||||||
local Gray = Core:Call("ReturnColorFromChar", nil, "8")
|
LOG("Debuggers: Calling Core.ReturnColorFromChar(..., \"8\")...")
|
||||||
if (Gray ~= cChatColor.Gray) then
|
local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", "split", "8")
|
||||||
LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "<nil>"))
|
|
||||||
else
|
|
||||||
LOGINFO("Call succeeded")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Use the new method:
|
|
||||||
LOGINFO("Calling Core::ReturnColorFromChar() the recommended way...")
|
|
||||||
local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", nil, "8")
|
|
||||||
if (Gray ~= cChatColor.Gray) then
|
if (Gray ~= cChatColor.Gray) then
|
||||||
LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "<nil>"))
|
LOGWARNING("Debuggers: Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "<nil>"))
|
||||||
else
|
else
|
||||||
LOGINFO("Call succeeded")
|
LOG("Debuggers: Call succeeded")
|
||||||
end
|
end
|
||||||
|
LOG("Debuggers: Inter-plugin calls done.")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1535,7 +1535,7 @@ int cLuaState::CallFunctionWithForeignParams(
|
||||||
if (!PushFunction(a_FunctionName.c_str()))
|
if (!PushFunction(a_FunctionName.c_str()))
|
||||||
{
|
{
|
||||||
LOGWARNING("Function '%s' not found", a_FunctionName.c_str());
|
LOGWARNING("Function '%s' not found", a_FunctionName.c_str());
|
||||||
lua_pop(m_LuaState, 2);
|
lua_settop(m_LuaState, OldTop);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1543,7 +1543,7 @@ int cLuaState::CallFunctionWithForeignParams(
|
||||||
if (CopyStackFrom(a_SrcLuaState, a_SrcParamStart, a_SrcParamEnd) < 0)
|
if (CopyStackFrom(a_SrcLuaState, a_SrcParamStart, a_SrcParamEnd) < 0)
|
||||||
{
|
{
|
||||||
// Something went wrong, fix the stack and exit
|
// Something went wrong, fix the stack and exit
|
||||||
lua_pop(m_LuaState, 2);
|
lua_settop(m_LuaState, OldTop);
|
||||||
m_NumCurrentFunctionArgs = -1;
|
m_NumCurrentFunctionArgs = -1;
|
||||||
m_CurrentFunctionName.clear();
|
m_CurrentFunctionName.clear();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1554,13 +1554,8 @@ int cLuaState::CallFunctionWithForeignParams(
|
||||||
if (ReportErrors(s))
|
if (ReportErrors(s))
|
||||||
{
|
{
|
||||||
LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str());
|
LOGWARN("Error while calling function '%s' in '%s'", a_FunctionName.c_str(), m_SubsystemName.c_str());
|
||||||
// Fix the stack.
|
// Reset the stack:
|
||||||
// We don't know how many values have been pushed, so just get rid of any that weren't there initially
|
lua_settop(m_LuaState, OldTop);
|
||||||
int CurTop = lua_gettop(m_LuaState);
|
|
||||||
if (CurTop > OldTop)
|
|
||||||
{
|
|
||||||
lua_pop(m_LuaState, CurTop - OldTop);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset the internal checking mechanisms:
|
// Reset the internal checking mechanisms:
|
||||||
m_NumCurrentFunctionArgs = -1;
|
m_NumCurrentFunctionArgs = -1;
|
||||||
|
|
|
@ -1988,6 +1988,11 @@ static int tolua_cPluginManager_CallPlugin(lua_State * tolua_S)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (Callback.m_NumReturns < 0)
|
||||||
|
{
|
||||||
|
// The call has failed, there are zero return values. Do NOT return negative number (Lua considers that a "yield")
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return Callback.m_NumReturns;
|
return Callback.m_NumReturns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user