-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClass.lua
38 lines (30 loc) · 992 Bytes
/
Class.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
sm._class = sm._class or class
local function emptyCtor() end
--- Extends the current class function with a callable constructor.
--- <br>The function is backwards compatible with the default implemenation.
--- @param superType? table Super class to inherit from
--- @return table @Prototype table representing the new class
function class(superType)
local proxy, newType = sm._class()
if superType ~= nil then
newType = superType._type ~= nil and sm._class(superType._type) or sm._class(superType)
else
newType = sm._class()
end
function proxy:__call(...)
newType.__init = newType.__init or emptyCtor
local instance = newType()
instance:__init(...)
return instance
end
function proxy:__index(key)
if (key == "_type") then
return newType
end
return newType[key]
end
function proxy:__newindex(key, value)
newType[key] = value
end
return proxy()
end