add data argument to inventory.add

This commit is contained in:
MihailRis 2025-02-16 03:31:06 +03:00
parent d25180406b
commit a118016c8f

View File

@ -81,10 +81,15 @@ static int l_add(lua::State* L) {
auto invid = lua::tointeger(L, 1); auto invid = lua::tointeger(L, 1);
auto itemid = lua::tointeger(L, 2); auto itemid = lua::tointeger(L, 2);
auto count = lua::tointeger(L, 3); auto count = lua::tointeger(L, 3);
auto data = lua::tovalue(L, 4);
validate_itemid(itemid); validate_itemid(itemid);
if (!data.isObject() && data != nullptr) {
throw std::runtime_error("invalid data argument type (table expected)");
}
auto& inv = get_inventory(invid); auto& inv = get_inventory(invid);
ItemStack item(itemid, count); ItemStack item(itemid, count, std::move(data));
inv.move(item, *indices); inv.move(item, *indices);
return lua::pushinteger(L, item.getCount()); return lua::pushinteger(L, item.getCount());
} }