diff options
Diffstat (limited to 'src/Bindings')
-rw-r--r-- | src/Bindings/AllToLua.pkg | 1 | ||||
-rw-r--r-- | src/Bindings/LuaState.cpp | 147 | ||||
-rw-r--r-- | src/Bindings/LuaState.h | 44 | ||||
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 4 | ||||
-rw-r--r-- | src/Bindings/Plugin.h | 2 | ||||
-rw-r--r-- | src/Bindings/PluginLua.cpp | 4 | ||||
-rw-r--r-- | src/Bindings/PluginLua.h | 2 | ||||
-rw-r--r-- | src/Bindings/PluginManager.cpp | 4 | ||||
-rw-r--r-- | src/Bindings/PluginManager.h | 2 |
9 files changed, 120 insertions, 90 deletions
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 1cd7c74f8..4fe86e1c5 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -76,6 +76,7 @@ $cfile "../CompositeChat.h" $cfile "../Map.h" $cfile "../MapManager.h" $cfile "../Scoreboard.h" +$cfile "../Statistics.h" diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index a33459ad2..7a5ed1425 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -372,11 +372,11 @@ void cLuaState::Push(const AStringVector & a_Vector) -void cLuaState::PushUserType(void * a_Object, const char * a_Type) +void cLuaState::Push(const cCraftingGrid * a_Grid) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Object, a_Type); + tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid"); m_NumCurrentFunctionArgs += 1; } @@ -384,11 +384,11 @@ void cLuaState::PushUserType(void * a_Object, const char * a_Type) -void cLuaState::Push(int a_Value) +void cLuaState::Push(const cCraftingRecipe * a_Recipe) { ASSERT(IsValid()); - tolua_pushnumber(m_LuaState, a_Value); + tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe"); m_NumCurrentFunctionArgs += 1; } @@ -396,11 +396,11 @@ void cLuaState::Push(int a_Value) -void cLuaState::Push(double a_Value) +void cLuaState::Push(const char * a_Value) { ASSERT(IsValid()); - tolua_pushnumber(m_LuaState, a_Value); + tolua_pushstring(m_LuaState, a_Value); m_NumCurrentFunctionArgs += 1; } @@ -408,11 +408,11 @@ void cLuaState::Push(double a_Value) -void cLuaState::Push(const char * a_Value) +void cLuaState::Push(const cItems & a_Items) { ASSERT(IsValid()); - tolua_pushstring(m_LuaState, a_Value); + tolua_pushusertype(m_LuaState, (void *)&a_Items, "cItems"); m_NumCurrentFunctionArgs += 1; } @@ -420,11 +420,11 @@ void cLuaState::Push(const char * a_Value) -void cLuaState::Push(bool a_Value) +void cLuaState::Push(const cPlayer * a_Player) { ASSERT(IsValid()); - tolua_pushboolean(m_LuaState, a_Value ? 1 : 0); + tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer"); m_NumCurrentFunctionArgs += 1; } @@ -432,11 +432,11 @@ void cLuaState::Push(bool a_Value) -void cLuaState::Push(cWorld * a_World) +void cLuaState::Push(const HTTPRequest * a_Request) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_World, "cWorld"); + tolua_pushusertype(m_LuaState, (void *)a_Request, "HTTPRequest"); m_NumCurrentFunctionArgs += 1; } @@ -444,11 +444,11 @@ void cLuaState::Push(cWorld * a_World) -void cLuaState::Push(cPlayer * a_Player) +void cLuaState::Push(const HTTPTemplateRequest * a_Request) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Player, "cPlayer"); + tolua_pushusertype(m_LuaState, (void *)a_Request, "HTTPTemplateRequest"); m_NumCurrentFunctionArgs += 1; } @@ -456,11 +456,11 @@ void cLuaState::Push(cPlayer * a_Player) -void cLuaState::Push(const cPlayer * a_Player) +void cLuaState::Push(const Vector3d & a_Vector) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer"); + tolua_pushusertype(m_LuaState, (void *)&a_Vector, "Vector3d"); m_NumCurrentFunctionArgs += 1; } @@ -468,11 +468,11 @@ void cLuaState::Push(const cPlayer * a_Player) -void cLuaState::Push(cEntity * a_Entity) +void cLuaState::Push(bool a_Value) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Entity, "cEntity"); + tolua_pushboolean(m_LuaState, a_Value ? 1 : 0); m_NumCurrentFunctionArgs += 1; } @@ -480,11 +480,11 @@ void cLuaState::Push(cEntity * a_Entity) -void cLuaState::Push(cProjectileEntity * a_ProjectileEntity) +void cLuaState::Push(cBlockEntity * a_BlockEntity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_ProjectileEntity, "cProjectileEntity"); + tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity"); m_NumCurrentFunctionArgs += 1; } @@ -492,11 +492,47 @@ void cLuaState::Push(cProjectileEntity * a_ProjectileEntity) -void cLuaState::Push(cMonster * a_Monster) +void cLuaState::Push(cChunkDesc * a_ChunkDesc) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Monster, "cMonster"); + tolua_pushusertype(m_LuaState, a_ChunkDesc, "cChunkDesc"); + m_NumCurrentFunctionArgs += 1; +} + + + + + +void cLuaState::Push(cClientHandle * a_Client) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, a_Client, "cClientHandle"); + m_NumCurrentFunctionArgs += 1; +} + + + + + +void cLuaState::Push(cEntity * a_Entity) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, a_Entity, "cEntity"); + m_NumCurrentFunctionArgs += 1; +} + + + + + +void cLuaState::Push(cHopperEntity * a_Hopper) +{ + ASSERT(IsValid()); + + tolua_pushusertype(m_LuaState, a_Hopper, "cHopperEntity"); m_NumCurrentFunctionArgs += 1; } @@ -528,11 +564,11 @@ void cLuaState::Push(cItems * a_Items) -void cLuaState::Push(const cItems & a_Items) +void cLuaState::Push(cMonster * a_Monster) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)&a_Items, "cItems"); + tolua_pushusertype(m_LuaState, a_Monster, "cMonster"); m_NumCurrentFunctionArgs += 1; } @@ -540,11 +576,11 @@ void cLuaState::Push(const cItems & a_Items) -void cLuaState::Push(cClientHandle * a_Client) +void cLuaState::Push(cPickup * a_Pickup) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Client, "cClientHandle"); + tolua_pushusertype(m_LuaState, a_Pickup, "cPickup"); m_NumCurrentFunctionArgs += 1; } @@ -552,11 +588,11 @@ void cLuaState::Push(cClientHandle * a_Client) -void cLuaState::Push(cPickup * a_Pickup) +void cLuaState::Push(cPlayer * a_Player) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Pickup, "cPickup"); + tolua_pushusertype(m_LuaState, a_Player, "cPlayer"); m_NumCurrentFunctionArgs += 1; } @@ -564,11 +600,11 @@ void cLuaState::Push(cPickup * a_Pickup) -void cLuaState::Push(cChunkDesc * a_ChunkDesc) +void cLuaState::Push(cPluginLua * a_Plugin) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_ChunkDesc, "cChunkDesc"); + tolua_pushusertype(m_LuaState, a_Plugin, "cPluginLua"); m_NumCurrentFunctionArgs += 1; } @@ -576,11 +612,11 @@ void cLuaState::Push(cChunkDesc * a_ChunkDesc) -void cLuaState::Push(const cCraftingGrid * a_Grid) +void cLuaState::Push(cProjectileEntity * a_ProjectileEntity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid"); + tolua_pushusertype(m_LuaState, a_ProjectileEntity, "cProjectileEntity"); m_NumCurrentFunctionArgs += 1; } @@ -588,11 +624,11 @@ void cLuaState::Push(const cCraftingGrid * a_Grid) -void cLuaState::Push(const cCraftingRecipe * a_Recipe) +void cLuaState::Push(cTNTEntity * a_TNTEntity) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe"); + tolua_pushusertype(m_LuaState, a_TNTEntity, "cTNTEntity"); m_NumCurrentFunctionArgs += 1; } @@ -600,11 +636,11 @@ void cLuaState::Push(const cCraftingRecipe * a_Recipe) -void cLuaState::Push(TakeDamageInfo * a_TDI) +void cLuaState::Push(cWebAdmin * a_WebAdmin) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_TDI, "TakeDamageInfo"); + tolua_pushusertype(m_LuaState, a_WebAdmin, "cWebAdmin"); m_NumCurrentFunctionArgs += 1; } @@ -624,11 +660,11 @@ void cLuaState::Push(cWindow * a_Window) -void cLuaState::Push(cPluginLua * a_Plugin) +void cLuaState::Push(cWorld * a_World) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Plugin, "cPluginLua"); + tolua_pushusertype(m_LuaState, a_World, "cWorld"); m_NumCurrentFunctionArgs += 1; } @@ -636,11 +672,11 @@ void cLuaState::Push(cPluginLua * a_Plugin) -void cLuaState::Push(const HTTPRequest * a_Request) +void cLuaState::Push(double a_Value) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)a_Request, "HTTPRequest"); + tolua_pushnumber(m_LuaState, a_Value); m_NumCurrentFunctionArgs += 1; } @@ -648,11 +684,11 @@ void cLuaState::Push(const HTTPRequest * a_Request) -void cLuaState::Push(cWebAdmin * a_WebAdmin) +void cLuaState::Push(int a_Value) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_WebAdmin, "cWebAdmin"); + tolua_pushnumber(m_LuaState, a_Value); m_NumCurrentFunctionArgs += 1; } @@ -660,11 +696,11 @@ void cLuaState::Push(cWebAdmin * a_WebAdmin) -void cLuaState::Push(const HTTPTemplateRequest * a_Request) +void cLuaState::Push(TakeDamageInfo * a_TDI) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, (void *)a_Request, "HTTPTemplateRequest"); + tolua_pushusertype(m_LuaState, a_TDI, "TakeDamageInfo"); m_NumCurrentFunctionArgs += 1; } @@ -672,11 +708,11 @@ void cLuaState::Push(const HTTPTemplateRequest * a_Request) -void cLuaState::Push(cTNTEntity * a_TNTEntity) +void cLuaState::Push(Vector3i * a_Vector) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_TNTEntity, "cTNTEntity"); + tolua_pushusertype(m_LuaState, a_Vector, "Vector3i"); m_NumCurrentFunctionArgs += 1; } @@ -684,11 +720,11 @@ void cLuaState::Push(cTNTEntity * a_TNTEntity) -void cLuaState::Push(Vector3i * a_Vector) +void cLuaState::Push(Vector3d * a_Vector) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_Vector, "Vector3i"); + tolua_pushusertype(m_LuaState, a_Vector, "Vector3d"); m_NumCurrentFunctionArgs += 1; } @@ -715,23 +751,12 @@ void cLuaState::Push(void * a_Ptr) -void cLuaState::Push(cHopperEntity * a_Hopper) -{ - ASSERT(IsValid()); - - tolua_pushusertype(m_LuaState, a_Hopper, "cHopperEntity"); - m_NumCurrentFunctionArgs += 1; -} - - - - -void cLuaState::Push(cBlockEntity * a_BlockEntity) +void cLuaState::PushUserType(void * a_Object, const char * a_Type) { ASSERT(IsValid()); - tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity"); + tolua_pushusertype(m_LuaState, a_Object, a_Type); m_NumCurrentFunctionArgs += 1; } diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index b9ca2f29b..066390e39 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -173,38 +173,42 @@ public: /** Returns true if a_FunctionName is a valid Lua function that can be called */ bool HasFunction(const char * a_FunctionName); - // Push a value onto the stack + // Push a const value onto the stack (keep alpha-sorted): 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 cCraftingGrid * a_Grid); + void Push(const cCraftingRecipe * a_Recipe); void Push(const char * a_Value); - void Push(bool a_Value); - void Push(cWorld * a_World); - void Push(cPlayer * a_Player); + void Push(const cItems & a_Items); void Push(const cPlayer * a_Player); + void Push(const HTTPRequest * a_Request); + void Push(const HTTPTemplateRequest * a_Request); + void Push(const Vector3d & a_Vector); + + // Push a value onto the stack (keep alpha-sorted): + void Push(bool a_Value); + void Push(cBlockEntity * a_BlockEntity); + void Push(cChunkDesc * a_ChunkDesc); + void Push(cClientHandle * a_ClientHandle); void Push(cEntity * a_Entity); - void Push(cProjectileEntity * a_ProjectileEntity); - void Push(cMonster * a_Monster); + void Push(cHopperEntity * a_Hopper); void Push(cItem * a_Item); void Push(cItems * a_Items); - void Push(const cItems & a_Items); - void Push(cClientHandle * a_ClientHandle); + void Push(cMonster * a_Monster); 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); - void Push(cWindow * a_Window); + void Push(cPlayer * a_Player); void Push(cPluginLua * a_Plugin); - void Push(const HTTPRequest * a_Request); - void Push(cWebAdmin * a_WebAdmin); - void Push(const HTTPTemplateRequest * a_Request); + void Push(cProjectileEntity * a_ProjectileEntity); void Push(cTNTEntity * a_TNTEntity); + void Push(cWebAdmin * a_WebAdmin); + void Push(cWindow * a_Window); + void Push(cWorld * a_World); + void Push(double a_Value); + void Push(int a_Value); + void Push(TakeDamageInfo * a_TDI); + void Push(Vector3d * a_Vector); void Push(Vector3i * a_Vector); void Push(void * a_Ptr); - void Push(cHopperEntity * a_Hopper); - void Push(cBlockEntity * a_BlockEntity); /** Retrieve value at a_StackPos, if it is a valid bool. If not, a_Value is unchanged */ void GetStackValue(int a_StackPos, bool & a_Value); diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 10e560ac0..14d9d16fc 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -2864,8 +2864,8 @@ static int tolua_cCompositeChat_SetMessageType(lua_State * tolua_S) } // Set the type: - int MessageType; - L.GetStackValue(1, MessageType); + int MessageType = mtCustom; + L.GetStackValue(2, MessageType); self->SetMessageType((eMessageType)MessageType); // Cut away everything from the stack except for the cCompositeChat instance; return that: diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h index 0bd9270c4..c6461c861 100644 --- a/src/Bindings/Plugin.h +++ b/src/Bindings/Plugin.h @@ -90,7 +90,7 @@ public: virtual bool OnPluginsLoaded (void) = 0; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) = 0; - virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) = 0; + virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) = 0; virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) = 0; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) = 0; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) = 0; diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp index 59708bf59..04639da60 100644 --- a/src/Bindings/PluginLua.cpp +++ b/src/Bindings/PluginLua.cpp @@ -1113,14 +1113,14 @@ bool cPluginLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a -bool cPluginLua::OnProjectileHitBlock(cProjectileEntity & a_Projectile) +bool cPluginLua::OnProjectileHitBlock(cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) { cCSLock Lock(m_CriticalSection); bool res = false; cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_BLOCK]; for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr) { - m_LuaState.Call((int)(**itr), &a_Projectile, cLuaState::Return, res); + m_LuaState.Call((int)(**itr), &a_Projectile, a_BlockX, a_BlockY, a_BlockZ, a_Face, a_BlockHitPos, cLuaState::Return, res); if (res) { return true; diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h index 3357dd87b..598e031c0 100644 --- a/src/Bindings/PluginLua.h +++ b/src/Bindings/PluginLua.h @@ -113,7 +113,7 @@ public: virtual bool OnPluginsLoaded (void) override; virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override; - virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile) override; + virtual bool OnProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) override; virtual bool OnProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity) override; virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override; virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override; diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index fc690d4de..acfc91bf8 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -1155,7 +1155,7 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti -bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile) +bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos) { HookMap::iterator Plugins = m_Hooks.find(HOOK_PROJECTILE_HIT_BLOCK); if (Plugins == m_Hooks.end()) @@ -1164,7 +1164,7 @@ bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile } for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr) { - if ((*itr)->OnProjectileHitBlock(a_Projectile)) + if ((*itr)->OnProjectileHitBlock(a_Projectile, a_BlockX, a_BlockY, a_BlockZ, a_Face, a_BlockHitPos)) { return true; } diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h index 3b3091957..be40bd2f7 100644 --- a/src/Bindings/PluginManager.h +++ b/src/Bindings/PluginManager.h @@ -206,7 +206,7 @@ public: // tolua_export bool CallHookPluginsLoaded (void); bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); - bool CallHookProjectileHitBlock (cProjectileEntity & a_Projectile); + bool CallHookProjectileHitBlock (cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos); bool CallHookProjectileHitEntity (cProjectileEntity & a_Projectile, cEntity & a_HitEntity); bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity); bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster); |