Skip to content

Instantly share code, notes, and snippets.

@Yonaba
Created September 13, 2013 11:52
Show Gist options
  • Save Yonaba/6549696 to your computer and use it in GitHub Desktop.
Save Yonaba/6549696 to your computer and use it in GitHub Desktop.
Plain Lua Inventory Class Example from MoonScript reference (http://moonscript.org/reference/#object_oriented_programming)
local Inventory = {}
Inventory.__index = Inventory
function Inventory:new()
local new_inventory = {}
new_inventory.items = {}
setmetatable(new_inventory, Inventory)
return new_inventory
end
function Inventory:add_item(name)
if self.items[name] then
self.items[name] = self.items[name] + 1
else
self.items[name] = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment