modlib/class.lua

26 lines
607 B
Lua
Raw Normal View History

2020-02-09 01:39:54 +01:00
classes = {}
function define(name, def)
if def.extends then
setmetatable(def, get(def.extends))
end
classes[name] = def
end
function new(classname, ...)
local obj = get(classname).new(...)
2020-03-23 20:20:43 +01:00
obj = setmetatable(obj, {__index = classes[classname]})
2020-02-09 01:39:54 +01:00
return obj
end
function get(classname)
return classes[classname]
end
function call(classname, funcname, object, ...)
if object then
setfenv(1, object)
get(classname)[funcname](object, ...)
else
setfenv(1, classes[classname])
get(classname)[funcname](...)
end
setfenv(1, _G)
end