Skip to content

Commit

Permalink
fix: add item:isContainer() function
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Sep 16, 2023
1 parent 91e280c commit 7d38564
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lua/functions/items/item_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,20 @@ int ItemFunctions::luaItemIsInsideDepot(lua_State* L) {
return 1;
}

int ItemFunctions::luaItemIsContainer(lua_State* L) {
// item:isContainer()
const auto item = getUserdata<const Item>(L, 1);
if (!item) {
reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND));
pushBoolean(L, false);
return 1;
}

const auto &it = Item::items[item->getID()];
pushBoolean(L, it.isContainer());
return 1;
}

int ItemFunctions::luaItemGetTier(lua_State* L) {
// item:getTier()
const Item* item = getUserdata<Item>(L, 1);
Expand Down
2 changes: 2 additions & 0 deletions src/lua/functions/items/item_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ItemFunctions final : LuaScriptInterface {
registerMethod(L, "Item", "setDuration", ItemFunctions::luaItemSetDuration);

registerMethod(L, "Item", "isInsideDepot", ItemFunctions::luaItemIsInsideDepot);
registerMethod(L, "Item", "isContainer", ItemFunctions::luaItemIsContainer);

registerMethod(L, "Item", "getTier", ItemFunctions::luaItemGetTier);
registerMethod(L, "Item", "setTier", ItemFunctions::luaItemSetTier);
Expand Down Expand Up @@ -145,6 +146,7 @@ class ItemFunctions final : LuaScriptInterface {
static int luaItemSetDuration(lua_State* L);

static int luaItemIsInsideDepot(lua_State* L);
static int luaItemIsContainer(lua_State* L);

static int luaItemGetTier(lua_State* L);
static int luaItemSetTier(lua_State* L);
Expand Down

0 comments on commit 7d38564

Please sign in to comment.