local class = { }
setmetatable(class, class)
--# Standard methods
--# virtual
function class:__call(...)
--# Call the constructor for a nice and clean syntax (class())
return self:construct(...)
end
--# virtual
function class:construct(...)
--# Constructs an object
local object = { }
setmetatable(object, self)
self.__index = self
local ok, err = pcall(self.init, object, ...)
if not ok then error(err, 2) end
return object
end
--# virtual
function class:init()
--# Standard constructor with no special construction
end
return class
Goal:
--# Constructing
local object = class()
local TestClass = class()
local InheritClass = TestClass()
--# Adding methods
function TestClass:method()
--# Do stuff
end
--# Adding metamethods
function TestClass:__tostring()
return "string"
end
The first things are working quite well, also with InheritClass, but the metamethods won't be inherited, because somehow, lua is ignoring the metatable of the metatable.
I could create methods for each metamethods and redirecting to the class itself, but then how would the index method or table work properly?
And with the current design, textutils screws up everything: It can't index a table with an index to itself and having itself as a metatable.
Any help appreciated and thank you for any answer.
Sewbacca