Bertram25/manaserv — comment on commit d73688d8ba0878cd5626532aa9d6ef363effcd5b
File: src/scripting/lua.cpp line 379
By bjorn:

I don't understand what you're trying to do here. `lua_settable` is documented as "Does the equivalent to `t[k] = v`, where `t` is the value at the given valid index, `v` is the value at the top of the stack, and `k` is the value just below the top. ". So the `tableStackPosition` part seems to be right, but what are your `k` and `v` supposed to be? Currently the value will be the amount and the key will be the item name, but all the other stuff you pushed to the stack is basically unused (table index, slot id and item id).

But you do leave it all on top of the stack, so when the function reaches the end and you return 1, probably the value at the top survives as return value, which is the id of the last item in the inventory.

Since an inventory entry consists of so many fields, what I think you'll want to do is to return a table of tables, where each table in the table represents an inventory item and has all those fields (slot, item_id, name, amount).