mirror of
https://github.com/Reuh/classtoi.git
synced 2025-10-27 20:29: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
|
for k, v in pairs(methods) do -- copy class methods
|
||||||
if k:sub(1, 1) ~= "!" then class[k] = v end -- except proxied methods
|
if k:sub(1, 1) ~= "!" then class[k] = v end -- except proxied methods
|
||||||
end
|
end
|
||||||
|
setmetatable(class, class)
|
||||||
for _, t in ipairs({...}) do -- fill super
|
for _, t in ipairs({...}) do -- fill super
|
||||||
if getmetatable(t) == nil then setmetatable(t, t) end -- auto-metatable the table
|
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
|
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.
|
-- 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
|
for _, metamethod in ipairs(metamethods) do
|
||||||
local inSuper = class:__index(metamethod)
|
local inSuper = class:__index(metamethod)
|
||||||
if class[metamethod] == nil and inSuper then
|
if inSuper and rawget(class, metamethod) == nil then
|
||||||
class[metamethod] = inSuper
|
rawset(class, metamethod, inSuper)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return setmetatable(class, class)
|
return class
|
||||||
end
|
end
|
||||||
|
|
||||||
--- The class which will be a parents for all the other classes.
|
--- The class which will be a parents for all the other classes.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue