summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-08-08 14:08:21 +0200
committermadmaxoft <github@xoft.cz>2013-08-08 14:08:35 +0200
commit198b221997e6f34131cf7078ad3616e5ff320c8d (patch)
tree9954a08f74e76d2284489e4a82ef2896c2675bca /source
parentcPlugin: Removed empty default implementation of virtual calls. (diff)
downloadcuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar.gz
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar.bz2
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar.lz
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar.xz
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.tar.zst
cuberite-198b221997e6f34131cf7078ad3616e5ff320c8d.zip
Diffstat (limited to '')
-rw-r--r--source/LuaState.cpp143
-rw-r--r--source/LuaState.h377
-rw-r--r--source/ManualBindings.cpp30
-rw-r--r--source/Plugin_NewLua.cpp911
4 files changed, 668 insertions, 793 deletions
diff --git a/source/LuaState.cpp b/source/LuaState.cpp
index d4beb249b..baa20fc07 100644
--- a/source/LuaState.cpp
+++ b/source/LuaState.cpp
@@ -32,6 +32,12 @@ extern "C"
+const cLuaState::cRet cLuaState::Return;
+
+
+
+
+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cLuaState:
@@ -272,7 +278,20 @@ bool cLuaState::PushFunctionFromRefTable(cRef & a_TableRef, const char * a_FnNam
-void cLuaState::PushStringVector(const AStringVector & a_Vector)
+void cLuaState::Push(const AString & a_String)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushcppstring(m_LuaState, a_String);
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(const AStringVector & a_Vector)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -305,7 +324,7 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type)
-void cLuaState::PushNumber(int a_Value)
+void cLuaState::Push(int a_Value)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -318,7 +337,7 @@ void cLuaState::PushNumber(int a_Value)
-void cLuaState::PushNumber(double a_Value)
+void cLuaState::Push(double a_Value)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -331,7 +350,7 @@ void cLuaState::PushNumber(double a_Value)
-void cLuaState::PushString(const char * a_Value)
+void cLuaState::Push(const char * a_Value)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -344,7 +363,7 @@ void cLuaState::PushString(const char * a_Value)
-void cLuaState::PushBool(bool a_Value)
+void cLuaState::Push(bool a_Value)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -357,7 +376,7 @@ void cLuaState::PushBool(bool a_Value)
-void cLuaState::PushObject(cWorld * a_World)
+void cLuaState::Push(cWorld * a_World)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -370,7 +389,7 @@ void cLuaState::PushObject(cWorld * a_World)
-void cLuaState::PushObject(cPlayer * a_Player)
+void cLuaState::Push(cPlayer * a_Player)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -383,7 +402,20 @@ void cLuaState::PushObject(cPlayer * a_Player)
-void cLuaState::PushObject(cEntity * a_Entity)
+void cLuaState::Push(const cPlayer * a_Player)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(cEntity * a_Entity)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -396,7 +428,7 @@ void cLuaState::PushObject(cEntity * a_Entity)
-void cLuaState::PushObject(cMonster * a_Monster)
+void cLuaState::Push(cMonster * a_Monster)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -409,7 +441,7 @@ void cLuaState::PushObject(cMonster * a_Monster)
-void cLuaState::PushObject(cItem * a_Item)
+void cLuaState::Push(cItem * a_Item)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -422,7 +454,7 @@ void cLuaState::PushObject(cItem * a_Item)
-void cLuaState::PushObject(cItems * a_Items)
+void cLuaState::Push(cItems * a_Items)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -435,7 +467,7 @@ void cLuaState::PushObject(cItems * a_Items)
-void cLuaState::PushObject(cClientHandle * a_Client)
+void cLuaState::Push(cClientHandle * a_Client)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -448,7 +480,7 @@ void cLuaState::PushObject(cClientHandle * a_Client)
-void cLuaState::PushObject(cPickup * a_Pickup)
+void cLuaState::Push(cPickup * a_Pickup)
{
ASSERT(IsValid());
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
@@ -461,6 +493,91 @@ void cLuaState::PushObject(cPickup * a_Pickup)
+void cLuaState::Push(cChunkDesc * a_ChunkDesc)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, a_ChunkDesc, "cChunkDesc");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(const cCraftingGrid * a_Grid)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(const cCraftingRecipe * a_Recipe)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::Push(TakeDamageInfo * a_TDI)
+{
+ ASSERT(IsValid());
+ ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
+
+ tolua_pushusertype(m_LuaState, a_TDI, "TakeDamageInfo");
+ m_NumCurrentFunctionArgs += 1;
+}
+
+
+
+
+
+void cLuaState::GetReturn(int a_StackPos, bool & a_ReturnedVal)
+{
+ a_ReturnedVal = (tolua_toboolean(m_LuaState, a_StackPos, a_ReturnedVal ? 1 : 0) > 0);
+}
+
+
+
+
+
+void cLuaState::GetReturn(int a_StackPos, AString & a_ReturnedVal)
+{
+ if (lua_isstring(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = tolua_tocppstring(m_LuaState, a_StackPos, a_ReturnedVal.c_str());
+ }
+}
+
+
+
+
+
+void cLuaState::GetReturn(int a_StackPos, int & a_ReturnedVal)
+{
+ if (lua_isnumber(m_LuaState, a_StackPos))
+ {
+ a_ReturnedVal = (int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal);
+ }
+}
+
+
+
+
+
bool cLuaState::CallFunction(int a_NumResults)
{
ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
diff --git a/source/LuaState.h b/source/LuaState.h
index 15dbdbc0e..8aa3f03d2 100644
--- a/source/LuaState.h
+++ b/source/LuaState.h
@@ -41,6 +41,10 @@ class cItem;
class cItems;
class cClientHandle;
class cPickup;
+class cChunkDesc;
+class cCraftingGrid;
+class cCraftingRecipe;
+struct TakeDamageInfo;
@@ -69,6 +73,14 @@ public:
cLuaState & m_LuaState;
int m_Ref;
} ;
+
+
+ /// A dummy class that's used only to delimit function args from return values for cLuaState::Call()
+ class cRet
+ {
+ } ;
+
+ static const cRet Return; // Use this constant to delimit function args from return values for cLuaState::Call()
/** Creates a new instance. The LuaState is not initialized.
@@ -124,33 +136,358 @@ public:
*/
bool PushFunctionFromRefTable(cRef & a_TableRef, const char * a_FnName);
- /// Pushes a string vector, as a table, onto the stack
- void PushStringVector(const AStringVector & a_Vector);
-
/// Pushes a usertype of the specified class type onto the stack
void PushUserType(void * a_Object, const char * a_Type);
+
+ // Push a value onto the stack
+ void Push(const AString & a_String);
+ void Push(const AStringVector & a_Vector);
+ void Push(int a_Value);
+ void Push(double a_Value);
+ void Push(const char * a_Value);
+ void Push(bool a_Value);
+ void Push(cWorld * a_World);
+ void Push(cPlayer * a_Player);
+ void Push(const cPlayer * a_Player);
+ void Push(cEntity * a_Entity);
+ void Push(cMonster * a_Monster);
+ void Push(cItem * a_Item);
+ void Push(cItems * a_Items);
+ void Push(cClientHandle * a_ClientHandle);
+ void Push(cPickup * a_Pickup);
+ void Push(cChunkDesc * a_ChunkDesc);
+ void Push(const cCraftingGrid * a_Grid);
+ void Push(const cCraftingRecipe * a_Recipe);
+ void Push(TakeDamageInfo * a_TDI);
- /// Pushes an integer onto the stack
- void PushNumber(int a_Value);
+ /// Call any 1-param 0-return Lua function in a single line:
+ template<
+ typename ArgT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ return CallFunction(0);
+ }
+
+ /// Call any 1-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 2-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 3-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
- /// Pushes a double onto the stack
- void PushNumber(double a_Value);
+ /// Call any 4-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
- /// Pushes a string onto the stack
- void PushString(const char * a_Value);
+ /// Call any 5-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 6-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
+ typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 7-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
+ typename ArgT7, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ Push(a_Arg7);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 8-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
+ typename ArgT7, typename ArgT8, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ Push(a_Arg7);
+ Push(a_Arg8);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 9-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
+ typename ArgT7, typename ArgT8, typename ArgT9, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ Push(a_Arg7);
+ Push(a_Arg8);
+ Push(a_Arg9);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 10-param 1-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5, typename ArgT6,
+ typename ArgT7, typename ArgT8, typename ArgT9, typename ArgT10, typename RetT1
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, ArgT10 a_Arg10, const cRet & a_Mark, RetT1 & a_Ret1)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ Push(a_Arg7);
+ Push(a_Arg8);
+ Push(a_Arg9);
+ Push(a_Arg10);
+ if (!CallFunction(1))
+ {
+ return false;
+ }
+ GetReturn(-1, a_Ret1);
+ lua_pop(m_LuaState, 1);
+ return true;
+ }
+
+ /// Call any 2-param 2-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename RetT1, typename RetT2
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ if (!CallFunction(2))
+ {
+ return false;
+ }
+ GetReturn(-2, a_Ret1);
+ GetReturn(-1, a_Ret2);
+ lua_pop(m_LuaState, 2);
+ return true;
+ }
+
+ /// Call any 9-param 5-return Lua function in a single line:
+ template<
+ typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4, typename ArgT5,
+ typename ArgT6, typename ArgT7, typename ArgT8, typename ArgT9,
+ typename RetT1, typename RetT2, typename RetT3, typename RetT4, typename RetT5
+ >
+ bool Call(const char * a_FnName, ArgT1 a_Arg1, ArgT2 a_Arg2, ArgT3 a_Arg3, ArgT4 a_Arg4, ArgT5 a_Arg5, ArgT6 a_Arg6, ArgT7 a_Arg7, ArgT8 a_Arg8, ArgT9 a_Arg9, const cRet & a_Mark, RetT1 & a_Ret1, RetT2 & a_Ret2, RetT3 & a_Ret3, RetT4 & a_Ret4, RetT5 & a_Ret5)
+ {
+ if (!PushFunction(a_FnName))
+ {
+ return false;
+ }
+ Push(a_Arg1);
+ Push(a_Arg2);
+ Push(a_Arg3);
+ Push(a_Arg4);
+ Push(a_Arg5);
+ Push(a_Arg6);
+ Push(a_Arg7);
+ Push(a_Arg8);
+ Push(a_Arg9);
+ if (!CallFunction(5))
+ {
+ return false;
+ }
+ GetReturn(-5, a_Ret1);
+ GetReturn(-4, a_Ret2);
+ GetReturn(-3, a_Ret3);
+ GetReturn(-2, a_Ret4);
+ GetReturn(-1, a_Ret5);
+ lua_pop(m_LuaState, 5);
+ return true;
+ }
+
+ /// Retrieve value returned at a_StackPos, if it is a valid bool. If not, a_ReturnedVal is unchanged
+ void GetReturn(int a_StackPos, bool & a_ReturnedVal);
- /// Pushes a bool onto the stack
- void PushBool(bool a_Value);
+ /// Retrieve value returned at a_StackPos, if it is a valid string. If not, a_ReturnedVal is unchanged
+ void GetReturn(int a_StackPos, AString & a_ReturnedVal);
- // Special family of functions that do PushUserType internally, but require one less parameter
- void PushObject(cWorld * a_World);
- void PushObject(cPlayer * a_Player);
- void PushObject(cEntity * a_Entity);
- void PushObject(cMonster * a_Monster);
- void PushObject(cItem * a_Item);
- void PushObject(cItems * a_Items);
- void PushObject(cClientHandle * a_ClientHandle);
- void PushObject(cPickup * a_Pickup);
+ /// Retrieve value returned at a_StackPos, if it is a valid number. If not, a_ReturnedVal is unchanged
+ void GetReturn(int a_StackPos, int & a_ReturnedVal);
/**
Calls the function that has been pushed onto the stack by PushFunction(),
diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp
index 4041ccc94..3c52d35f7 100644
--- a/source/ManualBindings.cpp
+++ b/source/ManualBindings.cpp
@@ -85,7 +85,7 @@ static int tolua_StringSplit(lua_State * tolua_S)
std::string delim = (std::string)tolua_tocppstring(LuaState, 2, 0);
AStringVector Split = StringSplit(str, delim);
- LuaState.PushStringVector(Split);
+ LuaState.Push(Split);
return 1;
}
@@ -1504,11 +1504,11 @@ public:
// No such function in the table, skip the callback
return false;
}
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
+ m_LuaState.Push(a_BlockX);
+ m_LuaState.Push(a_BlockY);
+ m_LuaState.Push(a_BlockZ);
+ m_LuaState.Push(a_BlockType);
+ m_LuaState.Push(a_BlockMeta);
if (!m_LuaState.CallFunction(1))
{
return false;
@@ -1529,9 +1529,9 @@ public:
// No such function in the table, skip the callback
return false;
}
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
+ m_LuaState.Push(a_BlockX);
+ m_LuaState.Push(a_BlockY);
+ m_LuaState.Push(a_BlockZ);
if (!m_LuaState.CallFunction(1))
{
return false;
@@ -1552,9 +1552,9 @@ public:
// No such function in the table, skip the callback
return false;
}
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
+ m_LuaState.Push(a_BlockX);
+ m_LuaState.Push(a_BlockY);
+ m_LuaState.Push(a_BlockZ);
if (!m_LuaState.CallFunction(1))
{
return false;
@@ -1575,9 +1575,9 @@ public:
// No such function in the table, skip the callback
return false;
}
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
+ m_LuaState.Push(a_BlockX);
+ m_LuaState.Push(a_BlockY);
+ m_LuaState.Push(a_BlockZ);
if (!m_LuaState.CallFunction(1))
{
return false;
diff --git a/source/Plugin_NewLua.cpp b/source/Plugin_NewLua.cpp
index a85d5aae9..02fb0bd3f 100644
--- a/source/Plugin_NewLua.cpp
+++ b/source/Plugin_NewLua.cpp
@@ -101,7 +101,7 @@ bool cPlugin_NewLua::Initialize(void)
-void cPlugin_NewLua::OnDisable()
+void cPlugin_NewLua::OnDisable(void)
{
cCSLock Lock(m_CriticalSection);
if (!m_LuaState.PushFunction("OnDisable", false)) // false = don't log error if not found
@@ -119,13 +119,7 @@ void cPlugin_NewLua::OnDisable()
void cPlugin_NewLua::Tick(float a_Dt)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_TICK);
- if (!m_LuaState.PushFunction(FnName))
- {
- return;
- }
- m_LuaState.PushNumber(a_Dt);
- m_LuaState.CallFunction(0);
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_TICK), a_Dt);
}
@@ -135,30 +129,9 @@ void cPlugin_NewLua::Tick(float a_Dt)
bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_BLOCK_TO_PICKUPS);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_World);
- m_LuaState.PushObject(a_Digger);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
- m_LuaState.PushObject(&a_Pickups);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_BLOCK_TO_PICKUPS), a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, &a_Pickups, cLuaState::Return, res);
+ return res;
}
@@ -168,6 +141,11 @@ bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHAT), a_Player, a_Message, cLuaState::Return, res, a_Message);
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -190,6 +168,7 @@ bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message)
}
lua_pop(m_LuaState, 2);
return bRetVal;
+ */
}
@@ -199,6 +178,14 @@ bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message)
bool cPlugin_NewLua::OnChunkAvailable(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ if (!m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHUNK_AVAILABLE), a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res))
+ {
+ return false;
+ }
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_AVAILABLE);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -218,6 +205,7 @@ bool cPlugin_NewLua::OnChunkAvailable(cWorld * a_World, int a_ChunkX, int a_Chun
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
+ */
}
@@ -227,6 +215,11 @@ bool cPlugin_NewLua::OnChunkAvailable(cWorld * a_World, int a_ChunkX, int a_Chun
bool cPlugin_NewLua::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATED), a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc, cLuaState::Return, res);
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATED);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -247,6 +240,7 @@ bool cPlugin_NewLua::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_Chun
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
+ */
}
@@ -256,6 +250,11 @@ bool cPlugin_NewLua::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_Chun
bool cPlugin_NewLua::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATING), a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc, cLuaState::Return, res);
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_GENERATING);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -276,6 +275,7 @@ bool cPlugin_NewLua::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_Chu
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
+ */
}
@@ -285,6 +285,14 @@ bool cPlugin_NewLua::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_Chu
bool cPlugin_NewLua::OnChunkUnloaded(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ if (!m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADED), a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res))
+ {
+ return false;
+ }
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADED);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -304,6 +312,7 @@ bool cPlugin_NewLua::OnChunkUnloaded(cWorld * a_World, int a_ChunkX, int a_Chunk
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
+ */
}
@@ -313,6 +322,14 @@ bool cPlugin_NewLua::OnChunkUnloaded(cWorld * a_World, int a_ChunkX, int a_Chunk
bool cPlugin_NewLua::OnChunkUnloading(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ if (!m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADING), a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res))
+ {
+ return false;
+ }
+ return res;
+}
+/*
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHUNK_UNLOADING);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -333,6 +350,7 @@ bool cPlugin_NewLua::OnChunkUnloading(cWorld * a_World, int a_ChunkX, int a_Chun
lua_pop(m_LuaState, 1);
return bRetVal;
}
+*/
@@ -341,6 +359,11 @@ bool cPlugin_NewLua::OnChunkUnloading(cWorld * a_World, int a_ChunkX, int a_Chun
bool cPlugin_NewLua::OnCollectingPickup(cPlayer * a_Player, cPickup * a_Pickup)
{
cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_COLLECTING_PICKUP), a_Player, a_Pickup, cLuaState::Return, res);
+ return res;
+
+ /*
const char * FnName = GetHookFnName(cPluginManager::HOOK_COLLECTING_PICKUP);
ASSERT(FnName != NULL);
if (!m_LuaState.PushFunction(FnName))
@@ -359,6 +382,7 @@ bool cPlugin_NewLua::OnCollectingPickup(cPlayer * a_Player, cPickup * a_Pickup)
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
lua_pop(m_LuaState, 1);
return bRetVal;
+ */
}
@@ -368,25 +392,12 @@ bool cPlugin_NewLua::OnCollectingPickup(cPlayer * a_Player, cPickup * a_Pickup)
bool cPlugin_NewLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_CRAFTING_NO_RECIPE);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushUserType((void *)a_Player, "cPlayer");
- m_LuaState.PushUserType((void *)a_Grid, "cCraftingGrid");
- m_LuaState.PushUserType((void *)a_Recipe, "cCraftingRecipe");
-
- if (!m_LuaState.CallFunction(1))
+ bool res = false;
+ if (!m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_CRAFTING_NO_RECIPE), (cPlayer *)a_Player, a_Grid, a_Recipe, cLuaState::Return, res))
{
return false;
}
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ return res;
}
@@ -396,24 +407,9 @@ bool cPlugin_NewLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftin
bool cPlugin_NewLua::OnDisconnect(cPlayer * a_Player, const AString & a_Reason)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_DISCONNECT);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_Player);
- m_LuaState.PushString(a_Reason.c_str());
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_DISCONNECT), a_Player, a_Reason, cLuaState::Return, res);
+ return res;
}
@@ -423,24 +419,9 @@ bool cPlugin_NewLua::OnDisconnect(cPlayer * a_Player, const AString & a_Reason)
bool cPlugin_NewLua::OnExecuteCommand(cPlayer * a_Player, const AStringVector & a_Split)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_EXECUTE_COMMAND);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_Player);
- m_LuaState.PushStringVector(a_Split);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_EXECUTE_COMMAND), a_Player, a_Split, cLuaState::Return, res);
+ return res;
}
@@ -450,24 +431,9 @@ bool cPlugin_NewLua::OnExecuteCommand(cPlayer * a_Player, const AStringVector &
bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Username)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_HANDSHAKE);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushUserType(a_Client, "cClientHandle");
- m_LuaState.PushString (a_Username.c_str());
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_HANDSHAKE), a_Client, a_Username, cLuaState::Return, res);
+ return res;
}
@@ -477,24 +443,9 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_KILLING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Victim);
- m_LuaState.PushObject(a_Killer);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_KILLING), &a_Victim, a_Killer, cLuaState::Return, res);
+ return res;
}
@@ -504,25 +455,9 @@ bool cPlugin_NewLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer)
bool cPlugin_NewLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_LOGIN);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_Client);
- m_LuaState.PushNumber(a_ProtocolVersion);
- m_LuaState.PushString(a_Username.c_str());
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_LOGIN), a_Client, a_ProtocolVersion, a_Username, cLuaState::Return, res);
+ return res;
}
@@ -532,29 +467,9 @@ bool cPlugin_NewLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, co
bool cPlugin_NewLua::OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_BREAKING_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_BREAKING_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -564,29 +479,9 @@ bool cPlugin_NewLua::OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int
bool cPlugin_NewLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_BROKEN_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_BROKEN_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -596,23 +491,9 @@ bool cPlugin_NewLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a
bool cPlugin_NewLua::OnPlayerEating(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_EATING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_EATING), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -622,23 +503,9 @@ bool cPlugin_NewLua::OnPlayerEating(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerJoined(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_JOINED);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_JOINED), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -648,28 +515,9 @@ bool cPlugin_NewLua::OnPlayerJoined(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_LEFT_CLICK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_Status);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_EATING), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status, cLuaState::Return, res);
+ return res;
}
@@ -679,23 +527,9 @@ bool cPlugin_NewLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_B
bool cPlugin_NewLua::OnPlayerMoved(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_MOVING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_MOVING), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -705,32 +539,9 @@ bool cPlugin_NewLua::OnPlayerMoved(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerPlacedBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_PLACED_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_PLACED_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -740,32 +551,9 @@ bool cPlugin_NewLua::OnPlayerPlacedBlock(cPlayer & a_Player, int a_BlockX, int a
bool cPlugin_NewLua::OnPlayerPlacingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_PLACING_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_PLACING_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -775,30 +563,9 @@ bool cPlugin_NewLua::OnPlayerPlacingBlock(cPlayer & a_Player, int a_BlockX, int
bool cPlugin_NewLua::OnPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
+ return res;
}
@@ -808,24 +575,9 @@ bool cPlugin_NewLua::OnPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_
bool cPlugin_NewLua::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushObject(&a_Entity);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY), &a_Player, &a_Entity, cLuaState::Return, res);
+ return res;
}
@@ -835,23 +587,9 @@ bool cPlugin_NewLua::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a
bool cPlugin_NewLua::OnPlayerShooting(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_SHOOTING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_SHOOTING), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -861,23 +599,9 @@ bool cPlugin_NewLua::OnPlayerShooting(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerSpawned(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_SPAWNED);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_SPAWNED), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -887,23 +611,9 @@ bool cPlugin_NewLua::OnPlayerSpawned(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerTossingItem(cPlayer & a_Player)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_TOSSING_ITEM);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_TOSSING_ITEM), &a_Player, cLuaState::Return, res);
+ return res;
}
@@ -913,32 +623,9 @@ bool cPlugin_NewLua::OnPlayerTossingItem(cPlayer & a_Player)
bool cPlugin_NewLua::OnPlayerUsedBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USED_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_USED_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -948,30 +635,9 @@ bool cPlugin_NewLua::OnPlayerUsedBlock(cPlayer & a_Player, int a_BlockX, int a_B
bool cPlugin_NewLua::OnPlayerUsedItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USED_ITEM);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_USED_ITEM), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
+ return res;
}
@@ -981,32 +647,9 @@ bool cPlugin_NewLua::OnPlayerUsedItem(cPlayer & a_Player, int a_BlockX, int a_Bl
bool cPlugin_NewLua::OnPlayerUsingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USING_BLOCK);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
- m_LuaState.PushNumber(a_BlockType);
- m_LuaState.PushNumber(a_BlockMeta);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_USING_BLOCK), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
+ return res;
}
@@ -1016,30 +659,9 @@ bool cPlugin_NewLua::OnPlayerUsingBlock(cPlayer & a_Player, int a_BlockX, int a_
bool cPlugin_NewLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PLAYER_USING_ITEM);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushNumber(a_BlockFace);
- m_LuaState.PushNumber(a_CursorX);
- m_LuaState.PushNumber(a_CursorY);
- m_LuaState.PushNumber(a_CursorZ);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_USING_ITEM), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
+ return res;
}
@@ -1049,25 +671,9 @@ bool cPlugin_NewLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_B
bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_POST_CRAFTING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushUserType((void *)a_Player, "cPlayer");
- m_LuaState.PushUserType((void *)a_Grid, "cCraftingGrid");
- m_LuaState.PushUserType((void *)a_Recipe, "cCraftingRecipe");
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_POST_CRAFTING), a_Player, a_Grid, a_Recipe, cLuaState::Return, res);
+ return res;
}
@@ -1077,25 +683,9 @@ bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGri
bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_PRE_CRAFTING);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushUserType((void *)a_Player, "cPlayer");
- m_LuaState.PushUserType((void *)a_Grid, "cCraftingGrid");
- m_LuaState.PushUserType((void *)a_Recipe, "cCraftingRecipe");
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PRE_CRAFTING), a_Player, a_Grid, a_Recipe, cLuaState::Return, res);
+ return res;
}
@@ -1105,24 +695,9 @@ bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid
bool cPlugin_NewLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNED_ENTITY);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
- m_LuaState.PushObject(&a_Entity);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_SPAWNED_ENTITY), &a_World, &a_Entity, cLuaState::Return, res);
+ return res;
}
@@ -1132,25 +707,9 @@ bool cPlugin_NewLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
bool cPlugin_NewLua::OnSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNED_MONSTER);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
- m_LuaState.PushObject(&a_Monster);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
- return false;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_SPAWNED_MONSTER), &a_World, &a_Monster, cLuaState::Return, res);
+ return res;
}
@@ -1160,25 +719,9 @@ bool cPlugin_NewLua::OnSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
bool cPlugin_NewLua::OnSpawningEntity(cWorld & a_World, cEntity & a_Entity)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNING_ENTITY);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
- m_LuaState.PushObject(&a_Entity);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
- return false;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_SPAWNING_ENTITY), &a_World, &a_Entity, cLuaState::Return, res);
+ return res;
}
@@ -1188,25 +731,9 @@ bool cPlugin_NewLua::OnSpawningEntity(cWorld & a_World, cEntity & a_Entity)
bool cPlugin_NewLua::OnSpawningMonster(cWorld & a_World, cMonster & a_Monster)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNING_MONSTER);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
- m_LuaState.PushObject(&a_Monster);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
- return false;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_SPAWNING_MONSTER), &a_World, &a_Monster, cLuaState::Return, res);
+ return res;
}
@@ -1216,24 +743,9 @@ bool cPlugin_NewLua::OnSpawningMonster(cWorld & a_World, cMonster & a_Monster)
bool cPlugin_NewLua::OnTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_TAKE_DAMAGE);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_Receiver);
- m_LuaState.PushUserType(&a_TDI, "TakeDamageInfo");
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) != 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_TAKE_DAMAGE), &a_Receiver, &a_TDI, cLuaState::Return, res);
+ return res;
}
@@ -1248,31 +760,9 @@ bool cPlugin_NewLua::OnUpdatedSign(
)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_UPDATED_SIGN);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_World);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushString(a_Line1.c_str());
- m_LuaState.PushString(a_Line2.c_str());
- m_LuaState.PushString(a_Line3.c_str());
- m_LuaState.PushString(a_Line4.c_str());
- m_LuaState.PushObject(a_Player);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_UPDATED_SIGN), a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player, cLuaState::Return, res);
+ return res;
}
@@ -1287,47 +777,9 @@ bool cPlugin_NewLua::OnUpdatingSign(
)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_UPDATING_SIGN);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(a_World);
- m_LuaState.PushNumber(a_BlockX);
- m_LuaState.PushNumber(a_BlockY);
- m_LuaState.PushNumber(a_BlockZ);
- m_LuaState.PushString(a_Line1.c_str());
- m_LuaState.PushString(a_Line2.c_str());
- m_LuaState.PushString(a_Line3.c_str());
- m_LuaState.PushString(a_Line4.c_str());
- m_LuaState.PushObject(a_Player);
-
- if (!m_LuaState.CallFunction(5))
- {
- return false;
- }
-
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -5, 0) > 0);
- if (lua_isstring(m_LuaState, -4))
- {
- a_Line1 = tolua_tostring(m_LuaState, -4, "");
- }
- if (lua_isstring(m_LuaState, -3))
- {
- a_Line2 = tolua_tostring(m_LuaState, -3, "");
- }
- if (lua_isstring(m_LuaState, -2))
- {
- a_Line3 = tolua_tostring(m_LuaState, -2, "");
- }
- if (lua_isstring(m_LuaState, -1))
- {
- a_Line4 = tolua_tostring(m_LuaState, -1, "");
- }
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_UPDATING_SIGN), a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player, cLuaState::Return, res, a_Line1, a_Line2, a_Line3, a_Line4);
+ return res;
}
@@ -1337,23 +789,9 @@ bool cPlugin_NewLua::OnUpdatingSign(
bool cPlugin_NewLua::OnWeatherChanged(cWorld & a_World)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
-
- if (!m_LuaState.CallFunction(1))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED), &a_World, cLuaState::Return, res);
+ return res;
}
@@ -1363,28 +801,11 @@ bool cPlugin_NewLua::OnWeatherChanged(cWorld & a_World)
bool cPlugin_NewLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather)
{
cCSLock Lock(m_CriticalSection);
- const char * FnName = GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGED);
- ASSERT(FnName != NULL);
- if (!m_LuaState.PushFunction(FnName))
- {
- return false;
- }
-
- m_LuaState.PushObject(&a_World);
- m_LuaState.PushNumber(a_NewWeather);
-
- if (!m_LuaState.CallFunction(2))
- {
- return false;
- }
-
- bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
- if (lua_isnumber(m_LuaState, -2))
- {
- a_NewWeather = (eWeather)lua_tointeger(m_LuaState, -2);
- }
- lua_pop(m_LuaState, 1);
- return bRetVal;
+ bool res = false;
+ int NewWeather = a_NewWeather;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_WEATHER_CHANGING), &a_World, a_NewWeather, cLuaState::Return, res, NewWeather);
+ a_NewWeather = (eWeather)NewWeather;
+ return res;
}
@@ -1410,8 +831,8 @@ bool cPlugin_NewLua::HandleCommand(const AStringVector & a_Split, cPlayer * a_Pl
return false;
}
- m_LuaState.PushStringVector(a_Split);
- m_LuaState.PushObject(a_Player);
+ m_LuaState.Push(a_Split);
+ m_LuaState.Push(a_Player);
// Call function:
if (!m_LuaState.CallFunction(1))
@@ -1448,7 +869,7 @@ bool cPlugin_NewLua::HandleConsoleCommand(const AStringVector & a_Split, cComman
// Push the function to be called:
m_LuaState.PushFunctionFromRegistry(cmd->second);
- m_LuaState.PushStringVector(a_Split);
+ m_LuaState.Push(a_Split);
// Call function:
if (!m_LuaState.CallFunction(2))
@@ -1721,8 +1142,8 @@ bool cPlugin_NewLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPla
cCSLock Lock(m_CriticalSection);
m_LuaState.PushFunctionFromRegistry(a_FnRef);
m_LuaState.PushUserType(&a_Window, "cWindow");
- m_LuaState.PushObject(&a_Player);
- m_LuaState.PushBool(a_CanRefuse);
+ m_LuaState.Push(&a_Player);
+ m_LuaState.Push(a_CanRefuse);
// Call function:
if (!m_LuaState.CallFunction(1))
@@ -1747,7 +1168,7 @@ void cPlugin_NewLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window,
cCSLock Lock(m_CriticalSection);
m_LuaState.PushFunctionFromRegistry(a_FnRef);
m_LuaState.PushUserType(&a_Window, "cWindow");
- m_LuaState.PushNumber(a_SlotNum);
+ m_LuaState.Push(a_SlotNum);
// Call function:
if (!m_LuaState.CallFunction(0))