- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.lua
More file actions
Latest commit
52 lines (45 loc) · 1016 Bytes
/
Copy pathclass.lua
File metadata and controls
52 lines (45 loc) · 1016 Bytes
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
-- oopsLua by ixtWuko
-- A simple OOP implement of Lua
---@classClass
---@fieldnewfun(...) : table
---@fieldisfun(Class : table) : boolean
localfunctionConstruct(cls, inst, ...)
ifcls.__basethen
Construct(cls.__base, inst, ...)
end
ifcls.ctorthen
cls.ctor(inst, ...)
end
end
localfunctionNew(cls)
returnfunction(...)
localinst= {}
setmetatable(inst, cls)
Construct(cls, inst,...)
returninst
end
end
localfunctionIsInstanceOf(inst, cls)
localproto=getmetatable(inst)
whileprotodo
ifproto==clsthen
returntrue
end
proto=proto.__base
end
returnfalse
end
---@paramnamestring
---@parambaseClass
---@returnClass
localfunctionclass(name, base)
localcls= { __class=name, __base=base }
ifbasethen
setmetatable(cls, base)
end
cls.__index=cls
cls.new=New(cls)
cls.is=IsInstanceOf
returncls
end
returnclass