so i called it bmclass
download Example1 - basic
Code: Select all
class = require("bmclass")
a = class("a")
function a:init(attrs)
self.x = attrs.x
self.y = attrs.y
print("for init")
end
function a:info()
print(tostring(self) .. " : Hello!!!")
print(self.x)
print(self.y)
end
b = a("b", {x = 100, y = 200}) -- output "for init"
b:info()
-- output
-- b : Hello!!!
-- 100
-- 200
print(b.x) -- output "100"
Example2 - Multiple inheritance
Code: Select all
class = require("bmclass")
a = class("a")
b = class("b")
c = class("c", a, b) -- superclass a and b
function a:init() print("a init") end
function b:init() print("b init") end
function c:init()
c:next(self, "init") -- next to the superclass
print("c init")
end
function a:hello1() print("Hello1") end
function b:hello2() print("Hello2") end
function c:hello3() print("Hello3") end
d = c("d")
-- output
-- a init
-- b init
-- c init
d:hello1() -- output "Hello1"
d:hello2() -- output "Hello2"
d:hello3() -- output "Hello3"
thanks