Skip to content

Commit

Permalink
Container: setCapacity new lua method
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-bernardo committed May 26, 2024
1 parent ce0cc0c commit 937e513
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Container : public Item, public Cylinder
size_t size() const { return itemlist.size(); }
bool empty() const { return itemlist.empty(); }
uint32_t capacity() const { return maxSize; }
void setCapacity(uint32_t capacity) { maxSize = capacity; }
uint32_t getAmmoCount() const { return ammoCount; }

ContainerIterator iterator() const;
Expand Down
15 changes: 15 additions & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,7 @@ void LuaScriptInterface::registerFunctions()

registerMethod("Container", "getSize", LuaScriptInterface::luaContainerGetSize);
registerMethod("Container", "getCapacity", LuaScriptInterface::luaContainerGetCapacity);
registerMethod("Container", "setCapacity", LuaScriptInterface::luaContainerSetCapacity);
registerMethod("Container", "getEmptySlots", LuaScriptInterface::luaContainerGetEmptySlots);
registerMethod("Container", "getItems", LuaScriptInterface::luaContainerGetItems);
registerMethod("Container", "getItemHoldingCount", LuaScriptInterface::luaContainerGetItemHoldingCount);
Expand Down Expand Up @@ -7378,6 +7379,20 @@ int LuaScriptInterface::luaContainerGetCapacity(lua_State* L)
return 1;
}

int LuaScriptInterface::luaContainerSetCapacity(lua_State* L)
{
// container:setCapacity(capacity)
Container* container = getUserdata<Container>(L, 1);
if (container) {
uint32_t capacity = getNumber<uint32_t>(L, 2);
container->setCapacity(capacity);
pushBoolean(L, true);
} else {
lua_pushnil(L);
}
return 1;
}

int LuaScriptInterface::luaContainerGetEmptySlots(lua_State* L)
{
// container:getEmptySlots([recursive = false])
Expand Down
1 change: 1 addition & 0 deletions src/luascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ class LuaScriptInterface

static int luaContainerGetSize(lua_State* L);
static int luaContainerGetCapacity(lua_State* L);
static int luaContainerSetCapacity(lua_State* L);
static int luaContainerGetEmptySlots(lua_State* L);
static int luaContainerGetItems(lua_State* L);
static int luaContainerGetItemHoldingCount(lua_State* L);
Expand Down

0 comments on commit 937e513

Please sign in to comment.