mirror of
https://github.com/Reuh/classtoi.git
synced 2025-10-27 12:19:31 +00:00
__inherit methods now receive an inheriting class with its metatable set
This commit is contained in:
parent
cc53045d4d
commit
4db788df32
1 changed files with 4 additions and 3 deletions
|
|
@ -139,6 +139,7 @@ function makeclass(...)
|
|||
for k, v in pairs(methods) do -- copy class methods
|
||||
if k:sub(1, 1) ~= "!" then class[k] = v end -- except proxied methods
|
||||
end
|
||||
setmetatable(class, class)
|
||||
for _, t in ipairs({...}) do -- fill super
|
||||
if getmetatable(t) == nil then setmetatable(t, t) end -- auto-metatable the table
|
||||
if type(t.__inherit) == "function" then t = t:__inherit(class) or t end -- call __inherit callback
|
||||
|
|
@ -147,11 +148,11 @@ function makeclass(...)
|
|||
-- Metamethods query are always raw and thefore don't follow our __index, so we need to manually define thoses.
|
||||
for _, metamethod in ipairs(metamethods) do
|
||||
local inSuper = class:__index(metamethod)
|
||||
if class[metamethod] == nil and inSuper then
|
||||
class[metamethod] = inSuper
|
||||
if inSuper and rawget(class, metamethod) == nil then
|
||||
rawset(class, metamethod, inSuper)
|
||||
end
|
||||
end
|
||||
return setmetatable(class, class)
|
||||
return class
|
||||
end
|
||||
|
||||
--- The class which will be a parents for all the other classes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue