From 9db307bb53677f1c3eaf34b03b77360b893a6482 Mon Sep 17 00:00:00 2001 From: faketruth Date: Sun, 2 Sep 2012 13:34:59 +0000 Subject: Exported cWorld::DoWithChestAt to Lua Exported cChestEntity to Lua for handling in DoWithChestAt git-svn-id: http://mc-server.googlecode.com/svn/trunk@820 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/AllToLua.pkg | 3 +- source/Bindings.cpp | 337 ++++++++++++++++++++++++++++++++++++++++++---- source/Bindings.h | 2 +- source/ManualBindings.cpp | 93 +++++++++++++ source/cChestEntity.h | 20 +-- 5 files changed, 416 insertions(+), 39 deletions(-) (limited to 'source') diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index 71d9cecb5..83f3a952c 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -29,6 +29,7 @@ $cfile "cServer.h" $cfile "cWorld.h" $cfile "cInventory.h" $cfile "cItem.h" +$cfile "cChestEntity.h" $cfile "cWebAdmin.h" $cfile "cWebPlugin.h" $cfile "cPickup.h" @@ -45,4 +46,4 @@ $cfile "cGroup.h" $cfile "BlockArea.h" $cfile "cLuaChunk.h" $cfile "CraftingRecipes.h" -$cfile "LuaItems.h" +$cfile "LuaItems.h" \ No newline at end of file diff --git a/source/Bindings.cpp b/source/Bindings.cpp index f1b850cb8..ed738a412 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 09/01/12 23:31:58. +** Generated automatically by tolua++-1.0.92 on 09/02/12 15:32:35. */ #ifndef __cplusplus @@ -38,6 +38,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); #include "cWorld.h" #include "cInventory.h" #include "cItem.h" +#include "cChestEntity.h" #include "cWebAdmin.h" #include "cWebPlugin.h" #include "cPickup.h" @@ -164,55 +165,60 @@ static void tolua_reg_types (lua_State* tolua_S) { tolua_usertype(tolua_S,"TakeDamageInfo"); tolua_usertype(tolua_S,"cCraftingRecipe"); - tolua_usertype(tolua_S,"cPlugin"); + tolua_usertype(tolua_S,"cPlugin_NewLua"); tolua_usertype(tolua_S,"cStringMap"); + tolua_usertype(tolua_S,"cLuaItems"); tolua_usertype(tolua_S,"cBlockArea"); + tolua_usertype(tolua_S,"cCraftingGrid"); + tolua_usertype(tolua_S,"Lua__cTCPLink"); tolua_usertype(tolua_S,"cServer"); tolua_usertype(tolua_S,"cRoot"); - tolua_usertype(tolua_S,"cLuaItems"); + tolua_usertype(tolua_S,"cGroup"); + tolua_usertype(tolua_S,"cTracer"); + tolua_usertype(tolua_S,"cMCLogger"); tolua_usertype(tolua_S,"cPlugin::CommandStruct"); tolua_usertype(tolua_S,"cPickup"); tolua_usertype(tolua_S,"cItems"); - tolua_usertype(tolua_S,"cCraftingGrid"); + tolua_usertype(tolua_S,"cCuboid"); tolua_usertype(tolua_S,"cClientHandle"); - tolua_usertype(tolua_S,"cMCLogger"); + tolua_usertype(tolua_S,"Vector3i"); tolua_usertype(tolua_S,"cFurnaceRecipe"); - tolua_usertype(tolua_S,"cGroup"); + tolua_usertype(tolua_S,"cStairs"); tolua_usertype(tolua_S,"cChatColor"); - tolua_usertype(tolua_S,"cTracer"); + tolua_usertype(tolua_S,"Lua__cPickup"); tolua_usertype(tolua_S,"cLuaChunk"); tolua_usertype(tolua_S,"Lua__cWebPlugin"); tolua_usertype(tolua_S,"Lua__cPawn"); - tolua_usertype(tolua_S,"cCuboid"); + tolua_usertype(tolua_S,"cTCPLink"); tolua_usertype(tolua_S,"cItem"); tolua_usertype(tolua_S,"Vector3f"); tolua_usertype(tolua_S,"cPlugin_Lua"); tolua_usertype(tolua_S,"cCraftingRecipes"); tolua_usertype(tolua_S,"Lua__cPlugin_NewLua"); - tolua_usertype(tolua_S,"Vector3i"); - tolua_usertype(tolua_S,"cPawn"); - tolua_usertype(tolua_S,"cWebAdmin"); - tolua_usertype(tolua_S,"Lua__cTCPLink"); - tolua_usertype(tolua_S,"cTCPLink"); tolua_usertype(tolua_S,"cGroupManager"); - tolua_usertype(tolua_S,"Lua__cPickup"); + tolua_usertype(tolua_S,"cChestEntity"); + tolua_usertype(tolua_S,"cWebAdmin"); + tolua_usertype(tolua_S,"cWebPlugin"); + tolua_usertype(tolua_S,"cBlockEntity"); + tolua_usertype(tolua_S,"cEntity"); + tolua_usertype(tolua_S,"HTTPFormData"); tolua_usertype(tolua_S,"Lua__cPlugin"); + tolua_usertype(tolua_S,"cWorld"); tolua_usertype(tolua_S,"cPluginManager"); - tolua_usertype(tolua_S,"Lua__cEntity"); tolua_usertype(tolua_S,"cLadder"); + tolua_usertype(tolua_S,"override"); tolua_usertype(tolua_S,"Lua__cPlayer"); - tolua_usertype(tolua_S,"cWebPlugin"); tolua_usertype(tolua_S,"cIniFile"); - tolua_usertype(tolua_S,"cEntity"); + tolua_usertype(tolua_S,"cPlugin"); tolua_usertype(tolua_S,"HTTPRequest"); tolua_usertype(tolua_S,"cVine"); tolua_usertype(tolua_S,"cPlayer"); tolua_usertype(tolua_S,"cTorch"); - tolua_usertype(tolua_S,"HTTPFormData"); + tolua_usertype(tolua_S,"cBlockEntityWindowOwner"); tolua_usertype(tolua_S,"cInventory"); - tolua_usertype(tolua_S,"cWorld"); - tolua_usertype(tolua_S,"cPlugin_NewLua"); - tolua_usertype(tolua_S,"cStairs"); + tolua_usertype(tolua_S,"Lua__cChestEntity"); + tolua_usertype(tolua_S,"cPawn"); + tolua_usertype(tolua_S,"Lua__cEntity"); tolua_usertype(tolua_S,"Vector3d"); } @@ -11669,14 +11675,14 @@ static int tolua_AllToLua_cWorld_GetSpawnX00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); + const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSpawnX'", NULL); #endif @@ -11701,14 +11707,14 @@ static int tolua_AllToLua_cWorld_GetSpawnY00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); + const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSpawnY'", NULL); #endif @@ -11733,14 +11739,14 @@ static int tolua_AllToLua_cWorld_GetSpawnZ00(lua_State* tolua_S) #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( - !tolua_isusertype(tolua_S,1,"cWorld",0,&tolua_err) || + !tolua_isusertype(tolua_S,1,"const cWorld",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - cWorld* self = (cWorld*) tolua_tousertype(tolua_S,1,0); + const cWorld* self = (const cWorld*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSpawnZ'", NULL); #endif @@ -13331,6 +13337,269 @@ static int tolua_set_cItem_m_ItemDamage(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: GetSlot of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_GetSlot00 +static int tolua_AllToLua_cChestEntity_GetSlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cChestEntity",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cChestEntity* self = (const cChestEntity*) tolua_tousertype(tolua_S,1,0); + int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetSlot'", NULL); +#endif + { + const cItem* tolua_ret = (const cItem*) self->GetSlot(a_Slot); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"const cItem"); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetSlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: SetSlot of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_SetSlot00 +static int tolua_AllToLua_cChestEntity_SetSlot00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"cItem",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,4,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); + int a_Slot = ((int) tolua_tonumber(tolua_S,2,0)); + cItem* a_Item = ((cItem*) tolua_tousertype(tolua_S,3,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetSlot'", NULL); +#endif + { + self->SetSlot(a_Slot,*a_Item); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'SetSlot'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: UsedBy of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_UsedBy00 +static int tolua_AllToLua_cChestEntity_UsedBy00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); + cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'UsedBy'", NULL); +#endif + { + self->UsedBy(a_Player); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'UsedBy'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: tolua_var_2 of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_get_cChestEntity_override +static int tolua_get_cChestEntity_override(lua_State* tolua_S) +{ + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'tolua_var_2'",NULL); +#endif + tolua_pushusertype(tolua_S,(void*)&self->tolua_var_2,"override"); + return 1; +} +#endif //#ifndef TOLUA_DISABLE + +/* set function: tolua_var_2 of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_set_cChestEntity_override +static int tolua_set_cChestEntity_override(lua_State* tolua_S) +{ + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable 'tolua_var_2'",NULL); + if ((tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"override",0,&tolua_err))) + tolua_error(tolua_S,"#vinvalid type in variable assignment.",&tolua_err); +#endif + self->tolua_var_2 = *((override*) tolua_tousertype(tolua_S,2,0)) +; + return 0; +} +#endif //#ifndef TOLUA_DISABLE + +/* method: GetChestHeight of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cChestEntity_GetChestHeight00 +static int tolua_AllToLua_cChestEntity_GetChestHeight00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cChestEntity",0,&tolua_err) || + !tolua_isnoobj(tolua_S,2,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChestHeight'", NULL); +#endif + { + int tolua_ret = (int) self->GetChestHeight(); + tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); + } + } + return 1; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'GetChestHeight'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* get function: __cBlockEntityWindowOwner__ of class cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_get_cChestEntity___cBlockEntityWindowOwner__ +static int tolua_get_cChestEntity___cBlockEntityWindowOwner__(lua_State* tolua_S) +{ + cChestEntity* self = (cChestEntity*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable '__cBlockEntityWindowOwner__'",NULL); +#endif +#ifdef __cplusplus + tolua_pushusertype(tolua_S,(void*)static_cast(self), "cBlockEntityWindowOwner"); +#else + tolua_pushusertype(tolua_S,(void*)((cBlockEntityWindowOwner*)self), "cBlockEntityWindowOwner"); +#endif + return 1; +} +#endif //#ifndef TOLUA_DISABLE + + class Lua__cChestEntity : public cChestEntity, public ToluaBase { +public: + void UsedBy( cPlayer* a_Player) { + if (push_method("UsedBy", tolua_AllToLua_cChestEntity_UsedBy00)) { + tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer"); + ToluaBase::dbcall(lua_state, 2, 0); + } else { + return ( void ) cChestEntity:: UsedBy(a_Player); + }; + }; + + void cChestEntity__UsedBy( cPlayer* a_Player) { + return ( void )cChestEntity::UsedBy(a_Player); + }; +}; + +/* method: tolua__set_instance of class Lua__cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00 +static int tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); + lua_State* L = tolua_S; + lua_Object lo = ((lua_Object) tolua_tovalue(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'tolua__set_instance'", NULL); +#endif + { + self->tolua__set_instance(L,lo); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'tolua__set_instance'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: cChestEntity__UsedBy of class Lua__cChestEntity */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00 +static int tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"Lua__cChestEntity",0,&tolua_err) || + !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + Lua__cChestEntity* self = (Lua__cChestEntity*) tolua_tousertype(tolua_S,1,0); + cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cChestEntity__UsedBy'", NULL); +#endif + { + self->cChestEntity__UsedBy(a_Player); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'cChestEntity__UsedBy'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* get function: Name of class HTTPFormData */ #ifndef TOLUA_DISABLE_tolua_get_HTTPFormData_Name static int tolua_get_HTTPFormData_Name(lua_State* tolua_S) @@ -21568,6 +21837,20 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_variable(tolua_S,"m_ItemHealth",tolua_get_cItem_m_ItemHealth,tolua_set_cItem_m_ItemHealth); tolua_variable(tolua_S,"m_ItemDamage",tolua_get_cItem_m_ItemDamage,tolua_set_cItem_m_ItemDamage); tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"cChestEntity","cChestEntity","cBlockEntity",NULL); + tolua_beginmodule(tolua_S,"cChestEntity"); + tolua_function(tolua_S,"GetSlot",tolua_AllToLua_cChestEntity_GetSlot00); + tolua_function(tolua_S,"SetSlot",tolua_AllToLua_cChestEntity_SetSlot00); + tolua_function(tolua_S,"UsedBy",tolua_AllToLua_cChestEntity_UsedBy00); + tolua_variable(tolua_S,"override",tolua_get_cChestEntity_override,tolua_set_cChestEntity_override); + tolua_function(tolua_S,"GetChestHeight",tolua_AllToLua_cChestEntity_GetChestHeight00); + tolua_variable(tolua_S,"__cBlockEntityWindowOwner__",tolua_get_cChestEntity___cBlockEntityWindowOwner__,NULL); + tolua_endmodule(tolua_S); + tolua_cclass(tolua_S,"Lua__cChestEntity","Lua__cChestEntity","cChestEntity",NULL); + tolua_beginmodule(tolua_S,"Lua__cChestEntity"); + tolua_function(tolua_S,"tolua__set_instance",tolua_AllToLua_Lua__cChestEntity_tolua__set_instance00); + tolua_function(tolua_S,"cChestEntity__UsedBy",tolua_AllToLua_Lua__cChestEntity_cChestEntity__UsedBy00); + tolua_endmodule(tolua_S); tolua_cclass(tolua_S,"HTTPFormData","HTTPFormData","",NULL); tolua_beginmodule(tolua_S,"HTTPFormData"); tolua_variable(tolua_S,"Name",tolua_get_HTTPFormData_Name,tolua_set_HTTPFormData_Name); diff --git a/source/Bindings.h b/source/Bindings.h index 2af2d69a7..635019a6a 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 09/01/12 23:31:58. +** Generated automatically by tolua++-1.0.92 on 09/02/12 15:32:36. */ /* Exported function */ diff --git a/source/ManualBindings.cpp b/source/ManualBindings.cpp index 5133d03c7..6e07b0aff 100644 --- a/source/ManualBindings.cpp +++ b/source/ManualBindings.cpp @@ -194,6 +194,95 @@ static int FNNAME(lua_State * tolua_S) \ +#define DEFINE_LUA_DOWITH_XYZ(CONTAINER,ITEM,FOREACH,FNNAME) \ + static int FNNAME(lua_State * tolua_S) \ + { \ + int NumArgs = lua_gettop(tolua_S) - 1; /* This includes 'self' */ \ + if ((NumArgs != 4) && (NumArgs != 5)) \ + { \ + LOGWARN("Error in function call '" #FOREACH "': Requires 4 or 5 arguments, got %i", NumArgs ); \ + return 0; \ + } \ + \ + CONTAINER * self = (CONTAINER *) tolua_tousertype(tolua_S, 1, 0); \ + if (!lua_isnumber(tolua_S, 2) || !lua_isnumber(tolua_S, 3) || !lua_isnumber(tolua_S, 4)) \ + { \ + LOGWARN("Error in function call '" #FOREACH "': Expected a number for parameters #1, #2 and #3"); \ + return 0; \ + } \ + \ + int ItemX = ((int)tolua_tonumber(tolua_S, 2, 0)); \ + int ItemY = ((int)tolua_tonumber(tolua_S, 3, 0)); \ + int ItemZ = ((int)tolua_tonumber(tolua_S, 4, 0)); \ + LOG("x %i y %i z %i", ItemX, ItemY, ItemZ ); \ + if (!lua_isfunction( tolua_S, 5)) \ + { \ + LOGWARN("Error in function call '" #FOREACH "': Expected a function for parameter #2"); \ + return 0; \ + } \ + \ + /* luaL_ref gets reference to value on top of the stack, the table is the last argument and therefore on the top */ \ + int TableRef = LUA_REFNIL; \ + if (NumArgs == 5) \ + { \ + TableRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); \ + if (TableRef == LUA_REFNIL) \ + { \ + LOGWARN("Error in function call '" #FOREACH "': Could not get value reference of parameter #3"); \ + return 0; \ + } \ + } \ + \ + /* table value is popped, and now function is on top of the stack */ \ + int FuncRef = luaL_ref(tolua_S, LUA_REGISTRYINDEX); \ + if (FuncRef == LUA_REFNIL) \ + { \ + LOGWARN("Error in function call '" #FOREACH "': Could not get function reference of parameter #2"); \ + return 0; \ + } \ + \ + class cLuaCallback : public cItemCallback \ + { \ + public: \ + cLuaCallback(lua_State* a_LuaState, int a_FuncRef, int a_TableRef) \ + : LuaState( a_LuaState ) \ + , FuncRef( a_FuncRef ) \ + , TableRef( a_TableRef ) \ + {} \ + \ + private: \ + virtual bool Item(ITEM * a_Item) override \ + { \ + lua_rawgeti( LuaState, LUA_REGISTRYINDEX, FuncRef); /* Push function reference */ \ + tolua_pushusertype(LuaState, a_Item, #ITEM); \ + if (TableRef != LUA_REFNIL) \ + { \ + lua_rawgeti( LuaState, LUA_REGISTRYINDEX, TableRef); /* Push table reference */ \ + } \ + \ + int s = lua_pcall(LuaState, (TableRef == LUA_REFNIL ? 1 : 2), 1, 0); \ + report_errors(LuaState, s); \ + return true; \ + } \ + lua_State * LuaState; \ + int FuncRef; \ + int TableRef; \ + } Callback(tolua_S, FuncRef, TableRef); \ + \ + bool bRetVal = self->FOREACH(ItemX, ItemY, ItemZ, Callback); \ + \ + /* Unreference the values again, so the LUA_REGISTRYINDEX can make place for other references */ \ + luaL_unref(tolua_S, LUA_REGISTRYINDEX, TableRef); \ + luaL_unref(tolua_S, LUA_REGISTRYINDEX, FuncRef); \ + \ + /* Push return value on stack */ \ + tolua_pushboolean(tolua_S, bRetVal ); \ + return 1; \ + } + + + + #define DEFINE_LUA_FOREACHINCHUNK(CONTAINER,ITEM,FOREACH,FNNAME) \ static int FNNAME(lua_State * tolua_S) \ @@ -386,6 +475,9 @@ DEFINE_LUA_DOWITH(cWorld, cPlayer, DoWithPlayer, tolua_cWorld_DoWithPlaye DEFINE_LUA_DOWITH(cWorld, cPlayer, FindAndDoWithPlayer, tolua_cWorld_FindAndDoWithPlayer); DEFINE_LUA_DOWITH(cRoot, cPlayer, FindAndDoWithPlayer, tolua_cRoot_FindAndDoWithPlayer); +// Define the DoWith...At enumerators: (takes one 3D coordinate and a callback class) +DEFINE_LUA_DOWITH_XYZ(cWorld, cChestEntity, DoWithChestAt, tolua_cWorld_DoWithChestAt ); + // Define the ForEach enumerators: DEFINE_LUA_FOREACH(cWorld, cPlayer, ForEachPlayer, tolua_cWorld_ForEachPlayer); DEFINE_LUA_FOREACH(cWorld, cEntity, ForEachEntity, tolua_cWorld_ForEachEntity); @@ -718,6 +810,7 @@ void ManualBindings::Bind( lua_State* tolua_S ) tolua_function(tolua_S, "ForEachFurnaceInChunk", tolua_cWorld_ForEachFurnaceInChunk); tolua_function(tolua_S, "DoWithPlayer", tolua_cWorld_DoWithPlayer); tolua_function(tolua_S, "FindAndDoWithPlayer", tolua_cWorld_FindAndDoWithPlayer); + tolua_function(tolua_S, "DoWithChestAt", tolua_cWorld_DoWithChestAt); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cPlugin"); diff --git a/source/cChestEntity.h b/source/cChestEntity.h index 9b747c184..b129bf429 100644 --- a/source/cChestEntity.h +++ b/source/cChestEntity.h @@ -22,10 +22,10 @@ class cNBTData; -class cChestEntity : - public cBlockEntity, - public cBlockEntityWindowOwner -{ +class cChestEntity : //tolua_export + public cBlockEntity, //tolua_export + public cBlockEntityWindowOwner //tolua_export +{ //tolua_export public: cChestEntity(int a_X, int a_Y, int a_Z, cWorld * a_World); virtual ~cChestEntity(); @@ -33,21 +33,21 @@ public: void HandleData( cNBTData* a_NBTData ); - const cItem * GetSlot( int a_Slot ) const; - void SetSlot( int a_Slot, cItem & a_Item ); + const cItem * GetSlot( int a_Slot ) const; //tolua_export + void SetSlot( int a_Slot, cItem & a_Item ); //tolua_export bool LoadFromJson( const Json::Value& a_Value ); virtual void SaveToJson(Json::Value& a_Value ) override; virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy( cPlayer * a_Player ) override; + virtual void UsedBy( cPlayer * a_Player ) override; //tolua_export - cChestEntity *GetJoinedChest() { return m_JoinedChest; } + cChestEntity * GetJoinedChest() { return m_JoinedChest; } // NOTE: Is this a safe function? Should it be exported to Lua? void SetJoinedChest(cChestEntity *a_Chest) { m_JoinedChest = a_Chest; } void RemoveJoinedChest(cChestEntity *a_Chest) { if (m_JoinedChest && m_JoinedChest == a_Chest) { m_JoinedChest = NULL; m_TopChest = false; } } - int GetChestHeight() { return ((m_JoinedChest) ? c_ChestHeight * 2 : c_ChestHeight); } + int GetChestHeight() { return ((m_JoinedChest) ? c_ChestHeight * 2 : c_ChestHeight); } //tolua_export cItem * GetContents(bool a_OnlyThis = false); static const int c_ChestWidth = 9; @@ -58,7 +58,7 @@ private: cItem * m_Content; bool m_TopChest; cChestEntity * m_JoinedChest; -}; +}; //tolua_export -- cgit v1.2.3