Created
September 13, 2013 11:52
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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