From 3e419ffb38df3f802ed30c5e114b8b3e8b7a6c1f Mon Sep 17 00:00:00 2001 From: darkrose Date: Sun, 3 Jun 2012 20:37:55 +1000 Subject: Add InvRef:is_empty(listname) and make chests/furnaces not diggable if not empty in minimal game --- src/scriptapi.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 9744aaa33..e231a9879 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -1718,6 +1718,20 @@ private: return 0; } + // is_empty(self, listname) -> true/false + static int l_is_empty(lua_State *L) + { + InvRef *ref = checkobject(L, 1); + const char *listname = luaL_checkstring(L, 2); + InventoryList *list = getlist(L, ref, listname); + if(list && list->getUsedSlots() > 0){ + lua_pushboolean(L, false); + } else { + lua_pushboolean(L, true); + } + return 1; + } + // get_size(self, listname) static int l_get_size(lua_State *L) { @@ -1944,6 +1958,7 @@ public: }; const char InvRef::className[] = "InvRef"; const luaL_reg InvRef::methods[] = { + method(InvRef, is_empty), method(InvRef, get_size), method(InvRef, set_size), method(InvRef, get_stack), -- cgit v1.2.3