blob: de36a43fa0d7ec0ae4f12cb234bdc32ad196fae8 (
plain)
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
46
|
--[[
Class model with inheritance and morphing support for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen
See LICENSE file for license details
]]--
local Object
local function class(base)
local cls = {}
function cls.super(obj)
return setmetatable(
{},
{
__index=function(t, k)
local v = base[k]
if type(v) ~= 'function' then return v end
return function(...)
local arg = {...}
arg[1] = obj
return v(unpack(arg))
end
end
}
)
end
function cls:morph(...)
setmetatable(self, {__index = cls})
self:init(...)
return self
end
local mt = {__call=function(self, ...) return cls.morph({}, ...) end}
if not base and Object then base = Object end
if base then mt.__index = base end
return setmetatable(cls, mt)
end
Object = class()
function Object:init(...) end
return class
|