1
0

Implemented cPluginManager:CallPlugin() API.

This function supersedes cPlugin:Call(), is safer to use in regards to multithreading and once again removes the need for the cPlugin class being exported at all.
This commit is contained in:
madmaxoft
2014-01-21 22:59:08 +01:00
parent 9c93ab15ab
commit 2a018cfa49
9 changed files with 508 additions and 217 deletions

View File

@@ -1469,6 +1469,40 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
int cPluginLua::CallFunctionFromForeignState(
const AString & a_FunctionName,
cLuaState & a_ForeignState,
int a_ParamStart,
int a_ParamEnd
)
{
cCSLock Lock(m_CriticalSection);
// Call the function:
int NumReturns = m_LuaState.CallFunctionWithForeignParams(a_FunctionName, a_ForeignState, a_ParamStart, a_ParamEnd);
if (NumReturns < 0)
{
// The call has failed, an error has already been output to the log, so just silently bail out with the same error
return NumReturns;
}
// Copy all the return values:
int Top = lua_gettop(m_LuaState);
int res = a_ForeignState.CopyStackFrom(m_LuaState, Top - NumReturns + 1, Top);
// Remove the return values off this stack:
if (NumReturns > 0)
{
lua_pop(m_LuaState, NumReturns);
}
return res;
}
AString cPluginLua::HandleWebRequest(const HTTPRequest * a_Request )
{
cCSLock Lock(m_CriticalSection);