Admittedly I am new-ish to Object programming and i am new to lua, i come from programming in javascript and PHP. Previously i've been using appcelerator for my projects, which is fine but sub-par for games. The forum has been helpful up to this point however im having difficulty understanding a few basic concepts that maybe someone(s) can shed some light on.
I guess the first is understanding classes despite scouring the internet and reading through articles.
What is the best practice method of creating static class variables? ex.
myclass.lua
-------
MyClass = Core.class()
function MyClass:init()
self.mystatic = 1
end
function: MyClass:someOtherMethod()
self.mystatic2 = self.mystatic2
end
------
I've seen a local table being used as storage but is this correct? should i be storing other objects in the same way?
local storage = {
myvar1 = "something"
refobj = someobject
}
My other thought is the use of metatables but honestly at this point i don't know what the best practice or simplest approaches are.
Any explanation is greatly appreciated.
Comments
For static variables you can use:
And I highly recommend Programming in Lua (2nd ed) to learn all the details of Lua 5.1.
MyClass.mystatic1 = MyExternalClass.new()
I get thrown a "attempt to index global 'MyExternalClass' (a nil value)" even though the file has not been excluded from execution (myexternalclass.lua).
Can you try this: (copy and modify from @atilim post above)