Lua doesn't have a set in stone version of how classes should be... That's the beauty of it. If you find a way to do it that suits your needs and you are comfortable with, then by all means I would say to roll with it. I like to do things myself and keep it simple, so I prefer not to use libraries like classic, 30log, or middleclass. This is the entirety of my class.lua that I drop into my projects:
local class = {}
function class:extend(subClass)
return setmetatable(subClass or {}, {__index = self})
end
function class:new(...)
local copy = setmetatable({}, {__index = self})
return copy, copy:init(...)
end
function class:init(...) end
return class
module(..., package.seeall) is discouraged. There's a huge and lengthy reason for it, but you don't need to know why right now unless you want (in which case you can start here: http://lua-users.org/wiki/LuaModuleFunctionCritiqued ). Also, the module function doesn't make classes, it makes modules.
As for classes, I highly recommend you use either kikito's middleclass or Yonaba's 30log. If you want to go your own way that's fine, but if you use these, then you can get a lot of help from people on this board (even from the library writers themselves). You own homebrewed class library would leave you to fend for yourself if you ran into problems.
Inny wrote:module(..., package.seeall) is discouraged. There's a huge and lengthy reason for it, but you don't need to know why right now unless you want (in which case you can start here: http://lua-users.org/wiki/LuaModuleFunctionCritiqued ). Also, the module function doesn't make classes, it makes modules.
As for classes, I highly recommend you use either kikito's middleclass or Yonaba's 30log. If you want to go your own way that's fine, but if you use these, then you can get a lot of help from people on this board (even from the library writers themselves). You own homebrewed class library would leave you to fend for yourself if you ran into problems.
Ohh I like Kikito's stuff, ill probably look at middleclass! I dont think I understand enough about lua to make my own class.lua lol
You might also consider using factory functions instead of classes if you don't need static class members. In other words, just write a function that creates, initializes, and returns a table, similar to what your class constructor would do (except create the table and return it instead of just initializing it). Inheritance can be achieved by writing factories that serve as decorators for tables created by other factories. This should produce very straightforward and understandable code, and won't require any special knowledge of Lua metatable stuff or any dependencies.