#define method(class, name) {#name, class::l_##name}
/*
- InvStack
+ ItemStack
*/
-class InvStack
+class ItemStack
{
private:
InventoryItem *m_stack;
// garbage collector
static int gc_object(lua_State *L) {
- InvStack *o = *(InvStack **)(lua_touserdata(L, 1));
+ ItemStack *o = *(ItemStack **)(lua_touserdata(L, 1));
delete o;
return 0;
}
// take_item(self)
static int l_take_item(lua_State *L)
{
- InvStack *o = checkobject(L, 1);
+ ItemStack *o = checkobject(L, 1);
push_stack_item(L, o->m_stack);
if(o->m_stack->getCount() == 1){
delete o->m_stack;
// put_item(self, item) -> true/false
static int l_put_item(lua_State *L)
{
- InvStack *o = checkobject(L, 1);
+ ItemStack *o = checkobject(L, 1);
InventoryItem *item = check_stack_item(L, 2);
if(!item){ // nil can always be inserted
lua_pushboolean(L, true);
}
public:
- InvStack(InventoryItem *item=NULL):
+ ItemStack(InventoryItem *item=NULL):
m_stack(item)
{
}
- ~InvStack()
+ ~ItemStack()
{
delete m_stack;
}
- static InvStack* checkobject(lua_State *L, int narg)
+ static ItemStack* checkobject(lua_State *L, int narg)
{
luaL_checktype(L, narg, LUA_TUSERDATA);
void *ud = luaL_checkudata(L, narg, className);
if(!ud) luaL_typerror(L, narg, className);
- return *(InvStack**)ud; // unbox pointer
+ return *(ItemStack**)ud; // unbox pointer
}
InventoryItem* getItemCopy()
return m_stack->clone();
}
- // Creates an InvStack and leaves it on top of stack
+ // Creates an ItemStack and leaves it on top of stack
static int create_object(lua_State *L)
{
InventoryItem *item = NULL;
}
}
}
- InvStack *o = new InvStack(item);
+ ItemStack *o = new ItemStack(item);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
lua_setmetatable(L, -2);
// Not callable from Lua
static int create(lua_State *L, InventoryItem *item)
{
- InvStack *o = new InvStack(item);
+ ItemStack *o = new ItemStack(item);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
lua_setmetatable(L, -2);
luaL_openlib(L, 0, methods, 0); // fill methodtable
lua_pop(L, 1); // drop methodtable
- // Can be created from Lua (InvStack::create(itemstring))
+ // Can be created from Lua (ItemStack::create(itemstring))
lua_register(L, className, create_object);
}
};
-const char InvStack::className[] = "InvStack";
-const luaL_reg InvStack::methods[] = {
- method(InvStack, take_item),
- method(InvStack, put_item),
+const char ItemStack::className[] = "ItemStack";
+const luaL_reg ItemStack::methods[] = {
+ method(ItemStack, take_item),
+ method(ItemStack, put_item),
{0,0}
};
int i = luaL_checknumber(L, 3);
InventoryItem *item = getitem(L, ref, listname, i);
if(!item){
- InvStack::create(L, NULL);
+ ItemStack::create(L, NULL);
return 1;
}
- InvStack::create(L, item->clone());
+ ItemStack::create(L, item->clone());
return 1;
}
InvRef *ref = checkobject(L, 1);
const char *listname = luaL_checkstring(L, 2);
int i = luaL_checknumber(L, 3);
- InvStack *stack = InvStack::checkobject(L, 4);
+ ItemStack *stack = ItemStack::checkobject(L, 4);
InventoryList *list = getlist(L, ref, listname);
if(!list){
lua_pushboolean(L, false);