Repository navigation
Expand file tree
/
Copy pathclass.lua
More file actions
78 lines (62 loc) · 2.02 KB
/
Copy pathclass.lua
File metadata and controls
78 lines (62 loc) · 2.02 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
local HTTPService = game:GetService("HttpService")
local ClassMetatable = {}
local Class = {}
function Class.allocate(extendClass)
return setmetatable({}, { __index = Class, __newindex = extendClass })
end
ClassMetatable.__class = "Class"
ClassMetatable.__index = Class
ClassMetatable.__tostring = function()
return ClassMetatable.__class
end
ClassMetatable.__call = Class.allocate
function Class.extend(className: string, extendClass)
extendClass = extendClass or Class
local newClassMetatable = {}
local newClass = {}
function newClass.allocate(class)
local newObject = { super = extendClass.allocate(class) }
setmetatable(newObject, { __index = newClass, __newindex = class })
return newObject
end
function newClass.new(...)
local newObjectMetatable = {}
local newObject = {}
newObject.super = extendClass.allocate(newObject)
newObjectMetatable.__guid = HTTPService:GenerateGUID(false)
newObjectMetatable.__object = className
newObjectMetatable.__index = newClass
newObjectMetatable.__tostring = newClass.__tostring or function()
return ("(Object: %s) %s"):format(newObjectMetatable.__object, newObjectMetatable.__guid)
end
for i,v in pairs(newClass) do
if i:find("__") then
newObjectMetatable[i] = v
end
end
setmetatable(newObject, newObjectMetatable)
newObject:init(...)
return newObject
end
function newClass.extend(className: string)
return Class.extend(className, newClass)
end
newClassMetatable.__guid = HTTPService:GenerateGUID(false)
newClassMetatable.__object = className
newClassMetatable.__index = function(_, name)
return rawget(extendClass, name)
end
newClassMetatable.__tostring = function()
return ("(Class) %s"):format(newClassMetatable.__object)
end
newClassMetatable.__call = function(_,...)
return newClass.new(...)
end
newClassMetatable.__eq = function(L, R)
return rawequal(getmetatable(L).__guid, getmetatable(R).__guid)
end
setmetatable(newClass, newClassMetatable)
return newClass
end
setmetatable(Class, ClassMetatable)
return Class