-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.lua
46 lines (40 loc) · 945 Bytes
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local function create_class(methods)
local class
class = setmetatable({
extend = function(child_methods)
child_methods.super = function(self, ...)
methods.construct(self, ...)
end
return create_class(setmetatable(child_methods, {
__index = methods
}))
end;
}, {
__call = function(_, ...)
local instance = setmetatable({}, {
__index = methods
})
instance:construct(...)
return instance
end
})
return class
end
local FallbackImage = create_class{
construct = function(self)
self.asset = 'foo'
end;
hehe = 1;
fnord = 1;
doo = function(self)
print(self.asset)
print(self.fnord)
end
}
local Rotz = FallbackImage.extend{
hehe = 2;
}
local i = FallbackImage()
print(i.fnord)
i:doo()
print(i.hehe)