summaryrefslogtreecommitdiffstats
path: root/src/Bindings/PluginLua.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-01-21 22:59:08 +0100
committermadmaxoft <github@xoft.cz>2014-01-21 23:00:35 +0100
commit2a018cfa49e0a85d2984f6daf6ee3c3372bdafda (patch)
treead5fd7e212a7256d3de42f101f3d74296f5b2425 /src/Bindings/PluginLua.cpp
parentFix a crash but somewhere... (diff)
downloadcuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar.gz
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar.bz2
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar.lz
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar.xz
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.tar.zst
cuberite-2a018cfa49e0a85d2984f6daf6ee3c3372bdafda.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/PluginLua.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 4c4664815..1d8c4c6ed 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -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);