Has anyone had any luck using OOP in love as outlined here? http://www.lua.org/pil/16.html
At a simple level it appears that I should be able to define a class like this:
Code: Select all
function MyClass:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end
function MyClass:subtract (v)
self.anumber = self.anumber - v
end
Code: Select all
myobject = MyClass:new(anumber = 10)
Code: Select all
myobject:subtract(7)
--myobject.anumber now = 3
Okay, next thing. It should be okay to do this right?
Code: Select all
mytable = {}
mytable[1] = MyClass:new(anumber = 20)
mytable[1]:subtract(10)
--mytable[1].anumber now = 10
(Note: This isn't the actual code in my program, but the reason I'm using these examples is that I want to make sure I have the principals down)