Can you clarify the meaning of this line in the spec:
It SHOULD NOT set any special functions, like metamethods
I don't know if my implementation violates this, since I use __call to instantiate my classes. Here is my class micro-library, base.lua:
return {
extend = function (self, subtype)
return setmetatable(subtype or {}, {
__index = self,
__call = function (self, ...)
local instance = setmetatable({}, { __index = self })
return instance, instance:constructor(...)
end
})
end,
constructor = function () end
}
And here is my class commons implementation:
if _G.common_class == false then return end
local Base = require 'base'
_G.common = {
class = function (name, class, superclass)
local c = Base.extend(superclass or Base, class)
c.constructor = class.init
return c
end,
instance = function (class, ...)
return (class(...))
end
}
This passes all the tests, but I worry that the __call metamethods on returned classes violate the spec. Am I misunderstanding the spec, or do I need to wrap my returned classes in an extra table or do something else in order not to violate the spec?
Can you clarify the meaning of this line in the spec:
I don't know if my implementation violates this, since I use
__callto instantiate my classes. Here is my class micro-library,base.lua:And here is my class commons implementation:
This passes all the tests, but I worry that the
__callmetamethods on returned classes violate the spec. Am I misunderstanding the spec, or do I need to wrap my returned classes in an extra table or do something else in order not to violate the spec?