summaryrefslogtreecommitdiffstats
path: root/source/PluginLua.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-12 22:24:59 +0200
committermadmaxoft <github@xoft.cz>2013-10-12 22:24:59 +0200
commit0352e4589882a070c5796f2604b9ad8f52a19f06 (patch)
treee92e6d56c007371a184076d1df352e9af257c278 /source/PluginLua.h
parentAPIDump: Added pretty-printing to code examples. (diff)
downloadcuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.gz
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.bz2
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.lz
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.xz
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.tar.zst
cuberite-0352e4589882a070c5796f2604b9ad8f52a19f06.zip
Diffstat (limited to '')
-rw-r--r--source/PluginLua.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/PluginLua.h b/source/PluginLua.h
index fee9c4986..d5d202bf0 100644
--- a/source/PluginLua.h
+++ b/source/PluginLua.h
@@ -137,6 +137,43 @@ public:
Returns true if the hook was added successfully.
*/
bool AddHookRef(int a_HookType, int a_FnRefIdx);
+
+ // The following templates allow calls to arbitrary Lua functions residing in the plugin:
+
+ /// Call a Lua function with 0 args
+ template <typename FnT> bool Call(FnT a_Fn)
+ {
+ cCSLock Lock(m_CriticalSection);
+ return m_LuaState.Call(a_Fn);
+ }
+
+ /// Call a Lua function with 1 arg
+ template <typename FnT, typename ArgT0> bool Call(FnT a_Fn, ArgT0 a_Arg0)
+ {
+ cCSLock Lock(m_CriticalSection);
+ return m_LuaState.Call(a_Fn, a_Arg0);
+ }
+
+ /// Call a Lua function with 2 args
+ template <typename FnT, typename ArgT0, typename ArgT1> bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1)
+ {
+ cCSLock Lock(m_CriticalSection);
+ return m_LuaState.Call(a_Fn, a_Arg0, a_Arg1);
+ }
+
+ /// Call a Lua function with 3 args
+ template <typename FnT, typename ArgT0, typename ArgT1, typename ArgT2> bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1, ArgT2 a_Arg2)
+ {
+ cCSLock Lock(m_CriticalSection);
+ return m_LuaState.Call(a_Fn, a_Arg0, a_Arg1, a_Arg2);
+ }
+
+ /// Call a Lua function with 4 args
+ template <typename FnT, typename ArgT0, typename ArgT1, typename ArgT2, typename ArgT3> bool Call(FnT a_Fn, ArgT0 a_Arg0, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_ArgT3)
+ {
+ cCSLock Lock(m_CriticalSection);
+ return m_LuaState.Call(a_Fn, a_Arg0, a_Arg1, a_Arg2, a_Arg3);
+ }
protected:
/// Maps command name into Lua function reference