From 7c0be7520ac70ceed378856aa95a062935d80442 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 1 Jun 2013 07:54:04 +0000 Subject: [PATCH] cItem constructor changed to create single-piece items when not given count http://forum.mc-server.org/showthread.php?tid=1150 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1536 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Bindings.cpp | 102 ++++++++++++++++++++++++++++++++++++-------- source/Bindings.h | 2 +- source/Item.h | 25 ++++++++--- 3 files changed, 106 insertions(+), 23 deletions(-) diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 417943226..28d691085 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 05/30/13 21:32:45. +** Generated automatically by tolua++-1.0.92 on 06/01/13 09:50:23. */ #ifndef __cplusplus @@ -13836,20 +13836,14 @@ static int tolua_AllToLua_cItem_new00(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertable(tolua_S,1,"cItem",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,1,&tolua_err) || - !tolua_isnumber(tolua_S,3,1,&tolua_err) || - !tolua_isnumber(tolua_S,4,1,&tolua_err) || - !tolua_isnoobj(tolua_S,5,&tolua_err) + !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - short a_ItemType = ((short) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); - char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,0)); - short a_ItemDamage = ((short) tolua_tonumber(tolua_S,4,0)); { - cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemDamage)); + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)()); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); } } @@ -13870,20 +13864,14 @@ static int tolua_AllToLua_cItem_new00_local(lua_State* tolua_S) tolua_Error tolua_err; if ( !tolua_isusertable(tolua_S,1,"cItem",0,&tolua_err) || - !tolua_isnumber(tolua_S,2,1,&tolua_err) || - !tolua_isnumber(tolua_S,3,1,&tolua_err) || - !tolua_isnumber(tolua_S,4,1,&tolua_err) || - !tolua_isnoobj(tolua_S,5,&tolua_err) + !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { - short a_ItemType = ((short) tolua_tonumber(tolua_S,2,E_ITEM_EMPTY)); - char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,0)); - short a_ItemDamage = ((short) tolua_tonumber(tolua_S,4,0)); { - cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemDamage)); + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)()); tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); } @@ -13897,6 +13885,65 @@ static int tolua_AllToLua_cItem_new00_local(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* method: new of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_new01 +static int tolua_AllToLua_cItem_new01(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,1,&tolua_err) || + !tolua_isnumber(tolua_S,4,1,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + short a_ItemType = ((short) tolua_tonumber(tolua_S,2,0)); + char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,1)); + short a_ItemDamage = ((short) tolua_tonumber(tolua_S,4,0)); + { + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemDamage)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cItem_new00(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + +/* method: new_local of class cItem */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_new01_local +static int tolua_AllToLua_cItem_new01_local(lua_State* tolua_S) +{ + tolua_Error tolua_err; + if ( + !tolua_isusertable(tolua_S,1,"cItem",0,&tolua_err) || + !tolua_isnumber(tolua_S,2,0,&tolua_err) || + !tolua_isnumber(tolua_S,3,1,&tolua_err) || + !tolua_isnumber(tolua_S,4,1,&tolua_err) || + !tolua_isnoobj(tolua_S,5,&tolua_err) + ) + goto tolua_lerror; + else + { + short a_ItemType = ((short) tolua_tonumber(tolua_S,2,0)); + char a_ItemCount = ((char) tolua_tonumber(tolua_S,3,1)); + short a_ItemDamage = ((short) tolua_tonumber(tolua_S,4,0)); + { + cItem* tolua_ret = (cItem*) Mtolua_new((cItem)(a_ItemType,a_ItemCount,a_ItemDamage)); + tolua_pushusertype(tolua_S,(void*)tolua_ret,"cItem"); + tolua_register_gc(tolua_S,lua_gettop(tolua_S)); + } + } + return 1; +tolua_lerror: + return tolua_AllToLua_cItem_new00_local(tolua_S); +} +#endif //#ifndef TOLUA_DISABLE + /* method: Empty of class cItem */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cItem_Empty00 static int tolua_AllToLua_cItem_Empty00(lua_State* tolua_S) @@ -26026,6 +26073,23 @@ static int tolua_AllToLua_cLuaWindow_GetContents00(lua_State* tolua_S) } #endif //#ifndef TOLUA_DISABLE +/* get function: __cItemGrid of class cLuaWindow */ +#ifndef TOLUA_DISABLE_tolua_get_cLuaWindow___cItemGrid__cListener__ +static int tolua_get_cLuaWindow___cItemGrid__cListener__(lua_State* tolua_S) +{ + cLuaWindow* self = (cLuaWindow*) tolua_tousertype(tolua_S,1,0); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable '__cItemGrid'",NULL); +#endif +#ifdef __cplusplus + tolua_pushusertype(tolua_S,(void*)static_cast(self), "cItemGrid::cListener"); +#else + tolua_pushusertype(tolua_S,(void*)((cItemGrid::cListener*)self), "cItemGrid::cListener"); +#endif + return 1; +} +#endif //#ifndef TOLUA_DISABLE + /* Open function */ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) { @@ -27194,6 +27258,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"new",tolua_AllToLua_cItem_new00); tolua_function(tolua_S,"new_local",tolua_AllToLua_cItem_new00_local); tolua_function(tolua_S,".call",tolua_AllToLua_cItem_new00_local); + tolua_function(tolua_S,"new",tolua_AllToLua_cItem_new01); + tolua_function(tolua_S,"new_local",tolua_AllToLua_cItem_new01_local); + tolua_function(tolua_S,".call",tolua_AllToLua_cItem_new01_local); tolua_function(tolua_S,"Empty",tolua_AllToLua_cItem_Empty00); tolua_function(tolua_S,"Clear",tolua_AllToLua_cItem_Clear00); tolua_function(tolua_S,"IsEmpty",tolua_AllToLua_cItem_IsEmpty00); @@ -27741,6 +27808,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,".call",tolua_AllToLua_cLuaWindow_new00_local); tolua_function(tolua_S,"delete",tolua_AllToLua_cLuaWindow_delete00); tolua_function(tolua_S,"GetContents",tolua_AllToLua_cLuaWindow_GetContents00); + tolua_variable(tolua_S,"__cItemGrid__cListener__",tolua_get_cLuaWindow___cItemGrid__cListener__,NULL); tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); return 1; diff --git a/source/Bindings.h b/source/Bindings.h index 0a25bec3d..6ec76cc1c 100644 --- a/source/Bindings.h +++ b/source/Bindings.h @@ -1,6 +1,6 @@ /* ** Lua binding: AllToLua -** Generated automatically by tolua++-1.0.92 on 05/30/13 21:32:45. +** Generated automatically by tolua++-1.0.92 on 06/01/13 09:50:24. */ /* Exported function */ diff --git a/source/Item.h b/source/Item.h index 9e37ce3bc..45b124e67 100644 --- a/source/Item.h +++ b/source/Item.h @@ -16,14 +16,29 @@ namespace Json class cItem { public: - cItem(short a_ItemType = E_ITEM_EMPTY, char a_ItemCount = 0, short a_ItemDamage = 0) - : m_ItemType (a_ItemType) - , m_ItemCount (a_ItemCount) - , m_ItemDamage(a_ItemDamage) + /// Creates an empty item + cItem(void) : + m_ItemType(E_ITEM_EMPTY), + m_ItemCount(0), + m_ItemDamage(0) + { + } + + + /// Creates an item of the specified type, by default 1 piece with no damage + cItem( + short a_ItemType, + char a_ItemCount = 1, + short a_ItemDamage = 0 + ) : + m_ItemType (a_ItemType), + m_ItemCount (a_ItemCount), + m_ItemDamage(a_ItemDamage) { if (!IsValidItem(m_ItemType)) { - m_ItemType = E_ITEM_EMPTY; + LOGWARNING("%s: creating an invalid item type (%d), resetting to empty.", __FUNCTION__, a_ItemType); + Empty(); } }