From 1ad6469a180dfe6932c756fe3c99bcada3ee0b7e Mon Sep 17 00:00:00 2001 From: andrew Date: Sat, 18 Jan 2014 16:59:33 +0200 Subject: Command blocks: Execute() --- src/Bindings/ManualBindings.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index ebee2d697..3ebe7b294 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -14,6 +14,7 @@ #include "../WebAdmin.h" #include "../ClientHandle.h" #include "../BlockEntities/ChestEntity.h" +#include "../BlockEntities/CommandBlockEntity.h" #include "../BlockEntities/DispenserEntity.h" #include "../BlockEntities/DropperEntity.h" #include "../BlockEntities/FurnaceEntity.h" @@ -2265,16 +2266,17 @@ void ManualBindings::Bind(lua_State * tolua_S) tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cWorld"); - tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithDropSpenserAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithDropperAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithEntityByID", tolua_DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>); - tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); - tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); - tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); + tolua_function(tolua_S, "DoWithBlockEntityAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithChestAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithDispenserAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithDropSpenserAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithDropperAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithEntityByID", tolua_DoWithID< cWorld, cEntity, &cWorld::DoWithEntityByID>); + tolua_function(tolua_S, "DoWithFurnaceAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithNoteBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithCommandBlockAt", tolua_DoWithXYZ); + tolua_function(tolua_S, "DoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::DoWithPlayer>); + tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_DoWith< cWorld, cPlayer, &cWorld::FindAndDoWithPlayer>); tolua_function(tolua_S, "ForEachBlockEntityInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachChestInChunk", tolua_ForEachInChunk); tolua_function(tolua_S, "ForEachEntity", tolua_ForEach< cWorld, cEntity, &cWorld::ForEachEntity>); -- cgit v1.2.3 From 24df625fbd86184b7a9404aab92a40ecfeaf455f Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sun, 19 Jan 2014 00:04:46 +0100 Subject: Exported cFloater to the Lua API. --- src/Bindings/AllToLua.pkg | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Bindings') diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg index 2d0300ebf..f65aed9bb 100644 --- a/src/Bindings/AllToLua.pkg +++ b/src/Bindings/AllToLua.pkg @@ -31,6 +31,7 @@ $cfile "../Defines.h" $cfile "../ChatColor.h" $cfile "../ClientHandle.h" $cfile "../Entities/Entity.h" +$cfile "../Entities/Floater.h" $cfile "../Entities/Pawn.h" $cfile "../Entities/Player.h" $cfile "../Entities/Pickup.h" -- cgit v1.2.3 From 4a01879911c5673612693531c4f8970c1644947b Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 19 Jan 2014 23:45:26 +0100 Subject: cLuaState can now check function params. --- src/Bindings/LuaState.cpp | 34 ++++++++++++++++++++++++++++++++++ src/Bindings/LuaState.h | 3 +++ 2 files changed, 37 insertions(+) (limited to 'src/Bindings') diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index 00e62fcf6..bfee1d037 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -914,6 +914,40 @@ bool cLuaState::CheckParamString(int a_StartParam, int a_EndParam) +bool cLuaState::CheckParamFunction(int a_StartParam, int a_EndParam) +{ + ASSERT(IsValid()); + + if (a_EndParam < 0) + { + a_EndParam = a_StartParam; + } + + for (int i = a_StartParam; i <= a_EndParam; i++) + { + if (lua_isfunction(m_LuaState, i)) + { + continue; + } + // Not the correct parameter + lua_Debug entry; + VERIFY(lua_getstack(m_LuaState, 0, &entry)); + VERIFY(lua_getinfo (m_LuaState, "n", &entry)); + AString ErrMsg = Printf("Error in function '%s' parameter #%d. Function expected, got %s", + (entry.name != NULL) ? entry.name : "?", i, GetTypeText(i).c_str() + ); + LogStackTrace(); + return false; + } // for i - Param + + // All params checked ok + return true; +} + + + + + bool cLuaState::CheckParamEnd(int a_Param) { tolua_Error tolua_err; diff --git a/src/Bindings/LuaState.h b/src/Bindings/LuaState.h index 414e5e4b2..f8b67f5cd 100644 --- a/src/Bindings/LuaState.h +++ b/src/Bindings/LuaState.h @@ -815,6 +815,9 @@ public: /// Returns true if the specified parameters on the stack are strings; also logs warning if not bool CheckParamString(int a_StartParam, int a_EndParam = -1); + /// Returns true if the specified parameters on the stack are functions; also logs warning if not + bool CheckParamFunction(int a_StartParam, int a_EndParam = -1); + /// Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) bool CheckParamEnd(int a_Param); -- cgit v1.2.3 From 41618bf242e66744431a1d28e0409f543fb240e4 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 19 Jan 2014 23:49:19 +0100 Subject: Changed the cWorld::ScheduleTask() signature. Now it takes the delay in ticks as an argument, and a cTask descendant as the task to run. Lua API has been updated similarly. --- src/Bindings/ManualBindings.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Bindings') diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 3ebe7b294..2206dd371 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -986,11 +986,10 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S) class cLuaScheduledWorldTask : - public cWorld::cScheduledTask + public cWorld::cTask { public: - cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef, int a_Ticks) : - cScheduledTask(a_Ticks), + cLuaScheduledWorldTask(cPluginLua & a_Plugin, int a_FnRef) : m_Plugin(a_Plugin), m_FnRef(a_FnRef) { @@ -1025,14 +1024,19 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) } // Retrieve the args: - cWorld * self = (cWorld *)tolua_tousertype(tolua_S, 1, 0); - if (self == NULL) + cLuaState L(tolua_S); + if ( + !L.CheckParamUserType(1, "cWorld") || + !L.CheckParamNumber (2) || + !L.CheckParamFunction(3) + ) { - return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); + return 0; } - if (!lua_isfunction(tolua_S, 2)) + cWorld * World = (cWorld *)tolua_tousertype(tolua_S, 1, NULL); + if (World == NULL) { - return lua_do_error(tolua_S, "Error in function call '#funcname#': Expected a function for parameter #1"); + return lua_do_error(tolua_S, "Error in function call '#funcname#': Not called on an object instance"); } // Create a reference to the function: @@ -1042,9 +1046,9 @@ static int tolua_cWorld_ScheduleTask(lua_State * tolua_S) return lua_do_error(tolua_S, "Error in function call '#funcname#': Could not get function reference of parameter #1"); } - int Ticks = (int) tolua_tonumber (tolua_S, 3, 0); + int DelayTicks = (int)tolua_tonumber(tolua_S, 2, 0); - self->ScheduleTask(new cLuaScheduledWorldTask(*Plugin, FnRef, Ticks)); + World->ScheduleTask(DelayTicks, new cLuaScheduledWorldTask(*Plugin, FnRef)); return 0; } -- cgit v1.2.3