fork/m-overlay

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

BkacjiosMore class changes27686d7

settings-overhaul
1.1 KiB47 linesraw
1local class = {
2	structs = {},
3	inherits = {},
4}
5
6function ACCESSOR(object, name, 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	if type(default) == "boolean" then
12		object["Is" .. name] = function(this) return this[internal] end
13	end
14	object["Get" .. name] = function(this) return this[internal] end
15	object["Set" .. name] = function(this, value) this[internal] = value end
16end
17
18local CLASS = {}
19CLASS.__index = CLASS
20
21function CLASS:ACCESSOR(name, internal, default)
22	return ACCESSOR(self, name, internal, default)
23end
24
25function CLASS:extends(basename)
26	class.inherits[self.__classname] = basename
27	return self
28end
29
30function class.create(classname, basename)
31	local struct = {}
32	struct.__classname = classname
33	struct.__constructor = classname
34	class.structs[classname] = struct
35	class.inherits[classname] = basename
36	return setmetatable(struct, CLASS)
37end
38
39function class.getStruct(classname)
40	return class.structs[classname]
41end
42
43function class.getBaseClassname(classname)
44	return class.inherits[classname]
45end
46
47return class