-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.lua
61 lines (48 loc) · 976 Bytes
/
syntax.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function class(kls, base)
if not base then
base = { }
end
kls.__index = function (self, key)
local get = function (this, key)
local t = rawget(this, key)
if t then return t end
t = kls[key]
if t then return t end
return base[key]
end
local t = get(self, 'get_' .. key)
if t then return t(self) end
return get(self, key)
end
kls.__newindex = function (self, key, value)
local t = rawget(self, 'set_' .. key)
if t then return t(self, value) end
rawset(self, key, value)
end
setmetatable(kls, base)
return kls
end
function new(kls, ...)
local obj = { }
setmetatable(obj, kls)
obj:new(...)
return obj
end
function is(obj, kls)
repeat
if obj == kls then
return true
end
obj = getmetatable(obj)
until not obj
return false
end
function call(fn, ...)
return fn(...)
end
function apply(fn, ...)
return fn(...)
end
function length(obj)
return #obj
end