diff options
author | archshift <admin@archshift.com> | 2014-07-29 22:04:00 +0200 |
---|---|---|
committer | archshift <admin@archshift.com> | 2014-07-29 22:04:00 +0200 |
commit | a9b597087b56b4526a3f6447789ba141568575a1 (patch) | |
tree | a08542d77b5668a25ca5e00492577ed6f4d61a9a /src/Bindings/LuaState.cpp | |
parent | Spacing fixes and a few more BLOCK_META constants. (diff) | |
parent | Slight cleanup after portals (diff) | |
download | cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar.gz cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar.bz2 cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar.lz cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar.xz cuberite-a9b597087b56b4526a3f6447789ba141568575a1.tar.zst cuberite-a9b597087b56b4526a3f6447789ba141568575a1.zip |
Diffstat (limited to 'src/Bindings/LuaState.cpp')
-rw-r--r-- | src/Bindings/LuaState.cpp | 166 |
1 files changed, 101 insertions, 65 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index a33459ad2..e123a87c9 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -40,7 +40,7 @@ const cLuaState::cRet cLuaState::Return = {}; -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cLuaState: cLuaState::cLuaState(const AString & a_SubsystemName) : @@ -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; } @@ -786,6 +811,18 @@ void cLuaState::GetStackValue(int a_StackPos, double & a_ReturnedVal) +void cLuaState::GetStackValue(int a_StackPos, eWeather & a_ReturnedVal) +{ + if (lua_isnumber(m_LuaState, a_StackPos)) + { + a_ReturnedVal = (eWeather)Clamp((int)tolua_tonumber(m_LuaState, a_StackPos, a_ReturnedVal), (int)wSunny, (int)wThunderstorm); + } +} + + + + + bool cLuaState::CallFunction(int a_NumResults) { ASSERT (m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first @@ -1299,9 +1336,8 @@ void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header) { UNUSED(a_Header); // The param seems unused when compiling for release, so the compiler warns - // Format string consisting only of %s is used to appease the compiler - LOGD("%s",(a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); + LOGD("%s", (a_Header != NULL) ? a_Header : "Lua C API Stack contents:"); for (int i = lua_gettop(a_LuaState); i > 0; i--) { AString Value; @@ -1334,7 +1370,7 @@ int cLuaState::ReportFnCallErrors(lua_State * a_LuaState) -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// // cLuaState::cRef: cLuaState::cRef::cRef(void) : |