LuaInventory

class LuaInventory
clear() Make this inventory empty.
can_insert(items) → boolean Can at least some items be inserted?
insert(items) → uint Insert items into this inventory.
remove(items) → uint Remove items from this inventory.
get_item_count(item) → uint Get the number of all or some items in this inventory.
is_empty() → boolean Does this inventory contain nothing?
get_contents() → dictionary stringuint Get counts of all items in this inventory.
hasbar() → boolean Does this inventory have a bar?
getbar() → uint Get the current bar.
setbar(bar) Set the current bar.
operator [] [RW] The indexing operator.
operator # [R] Get the number of slots in this inventory.

A storage of item stacks.

clear()

Make this inventory empty.

can_insert(items) → boolean

Can at least some items be inserted?

Parameters
items :: SimpleItemStack: Items that would be inserted.
Return value
true if at least a part of the given items could be inserted into this inventory.
insert(items) → uint

Insert items into this inventory.

Parameters
items :: SimpleItemStack: Items to insert.
Return value
Number of items actually inserted.
remove(items) → uint

Remove items from this inventory.

Parameters
items :: SimpleItemStack: Items to remove.
Return value
Number of items actually removed.
get_item_count(item) → uint

Get the number of all or some items in this inventory.

Parameters
item :: string (optional): Prototype name of the item to count. If not specified, count all items.
is_empty() → boolean

Does this inventory contain nothing?

get_contents() → dictionary stringuint

Get counts of all items in this inventory.

Return value
The counts, indexed by item names.
hasbar() → boolean

Does this inventory have a bar? Bar is the draggable red thing, found for example on chests, that limits the portion of the inventory that may be manipulated by machines.

Note: "Having a bar" doesn't mean that the bar is set to some nontrivial value. Having a bar means the inventory supports having this limit at all. The character's inventory is an example of an inventory without a bar; the wooden chest's inventory is an example of one with a bar.
getbar() → uint

Get the current bar. This is the index at which the red area starts.

Note: Only useable if this inventory has a bar.
setbar(bar)

Set the current bar.

Parameters
bar :: uint (optional): The new limit. Ommitting this parameter will clear the limit.
Note: Only useable if this inventory has a bar.
operator [] [Read-Write]

The indexing operator.

Example
Will get the first item in the player's quickbar.
game.local_player.get_inventory(defines.inventory.player_quickbar)[1]
operator # [Read-only]

Get the number of slots in this inventory.

Example
Will print the number of slots in the player's main inventory.
game.local_player.print(#game.local_player.get_inventory(defines.inventory.player_main))