olegharput
Newcomer
- Joined
- Mar 23, 2021
- Messages
- 1
- Reaction score
- 0
i can not set metatable in this code, i can not find the issue here. Need help
the Code:
and the output which is not true is: => Nil
i think it should be "private" but it is nil which means the metatable is not set.
What is the issue here?
the Code:
Code:
local CLASS = {
type = "CLASS",
mt = {},
newClass = function (self, type)
local aaa = {}
setmetatable(aaa, CLASS)
for k, v in pairs(self) do
aaa[k] = v
end
aaa.type = type
aaa.super = self.type
print("a new class named " .. type .. " created from the class " .. aaa.super)
return aaa
end,
newInstance = function (self)
local bbb = {}
for k, v in pairs(self) do
bbb[k] = v
end
print("a new instance for class " .. self.type .. " is created ")
return bbb
end,
getTypeOfTheInstance = function (self)
return self.type
end
}
local PLAYER = CLASS:newClass("PLAYER")
local p1 = PLAYER:newInstance()
CLASS.mt.__metatable = "private"
print(getmetatable(CLASS))
return CLASS
and the output which is not true is: => Nil
i think it should be "private" but it is nil which means the metatable is not set.
What is the issue here?