From d5ba7ebaf0683560cc93b650c5b9499fbcdacff7 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 6 Dec 2011 17:23:58 +0200 Subject: Random fixes to InvRef related stuff and a broken luafurnace --- src/scriptapi.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 101e07894..2efb8203d 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -606,7 +606,7 @@ static void push_stack_item(lua_State *L, InventoryItem *item0) if(item0 == NULL){ lua_pushnil(L); } - if(std::string("MaterialItem") == item0->getName()){ + else if(std::string("MaterialItem") == item0->getName()){ MaterialItem *item = (MaterialItem*)item0; lua_newtable(L); lua_pushstring(L, "NodeItem"); @@ -837,6 +837,14 @@ private: return 0; } + // peek_item(self) + static int l_peek_item(lua_State *L) + { + ItemStack *o = checkobject(L, 1); + push_stack_item(L, o->m_stack); + return 1; + } + // take_item(self) static int l_take_item(lua_State *L) { @@ -870,6 +878,29 @@ private: return 1; } + // put_stackstring(self, stackstring) -> true/false + static int l_put_stackstring(lua_State *L) + { + ItemStack *o = checkobject(L, 1); + std::string stackstring = luaL_checkstring(L, 2); + try{ + InventoryItem *item = InventoryItem::deSerialize(stackstring, + get_server(L)); + if(!item->addableTo(o->m_stack)){ + lua_pushboolean(L, false); + return 1; + } + o->m_stack->add(1); + delete item; + lua_pushboolean(L, true); + return 1; + } + catch(SerializationError &e){ + lua_pushboolean(L, false); + return 1; + } + } + public: ItemStack(InventoryItem *item=NULL): m_stack(item) @@ -956,8 +987,10 @@ public: }; const char ItemStack::className[] = "ItemStack"; const luaL_reg ItemStack::methods[] = { + method(ItemStack, peek_item), method(ItemStack, take_item), method(ItemStack, put_item), + method(ItemStack, put_stackstring), {0,0} }; @@ -1317,7 +1350,6 @@ private: // set_infotext(self, text) static int l_set_infotext(lua_State *L) { - infostream<<__FUNCTION_NAME<m_p); + return 1; + } + + // deprecated: inventory_set_list(self, name, {item1, item2, ...}) static int l_inventory_set_list(lua_State *L) { + infostream<<"Deprecated: inventory_set_list"<