fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosBugfixes + Dark Mode skina8034e9

v2.1.6
1.2 KiB56 linesraw
1local class = {
2	structs = {},
3	inherits = {},
4}
5
6function ACCESSOR(object, field, internal, default)
7	if not object then
8		return error("attempt to call ACCESSOR on a nil value")
9	end
10	object[internal] = default
11
12	local getter = function(this) return this[internal] end
13	local setter = function(this, value) this[internal] = value end
14
15	if type(default) == "boolean" then
16		object["Is" .. field] = getter
17	end
18	object["Get" .. field] = getter
19	object["Set" .. field] = setter
20end
21
22local STRUCT = {}
23STRUCT.__index = STRUCT
24
25function STRUCT:ACCESSOR(field, internal, default)
26	if type(field) == "table" then
27		for k,v in pairs(field) do
28			ACCESSOR(self, v, internal, default)
29		end
30	elseif type(field) == "string" then
31		ACCESSOR(self, field, internal, default)
32	end
33end
34
35function STRUCT:extends(basename)
36	class.inherits[self.classname] = basename
37	return self
38end
39
40function class.create(classname, basename)
41	local struct = {}
42	struct.classname = classname
43	class.structs[classname] = struct
44	class.inherits[classname] = basename
45	return setmetatable(struct, STRUCT)
46end
47
48function class.get(classname)
49	return class.structs[classname]
50end
51
52function class.getBase(classname)
53	return class.inherits[classname]
54end
55
56return class