Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _G = _G
- local super_t = {}
- local super_mt = {
- __index = function(obj, field)
- local cls = class.super
- while(cls) do
- if cls.public[field] then return cls.public[field] end
- if cls.protected[field] then return cls.protected[field] end
- cls = cls.super
- end
- return nil
- end
- }
- setmetatable(super_t, super_mt)
- local Object_mt = {
- __index = function(obj, field)
- print(obj, field)
- local cls = obj.class
- local f
- if obj == _ENV and cls.private[field] then f = cls.private[field]
- else
- while cls do
- if cls.public[field] then
- f = cls.public[field]
- break
- elseif obj == _ENV and cls.protected[field] then
- f = cls.protected[field]
- break
- end
- cls = cls.super
- end
- end
- print(f)
- if f == nil then return _G[field] end
- print(f)
- if type(f) == "function" then
- return function(...)
- local olde = _ENV
- print(_ENV)
- print(obj)
- _ENV = obj
- print(_ENV)
- local ret = f(...)
- _ENV = olde
- return ret
- end
- end
- return f
- end
- }
- local Object = {}
- local classes = {}
- function class(name)
- local super
- local function func(o)
- if type(o) == "string" then
- super = o
- elseif type(o) == "table" then
- classes[name] = o
- setmetatable(o, {__index = super and classes[super] or Object})
- o.public = o.public or {}
- o.private = o.private or {}
- o.protected = o.protected or {}
- end
- return func
- end
- return func
- end
- _G.class = class
- function new(class)
- local cls = {}
- cls.class = classes[class] or Object
- cls.super = super_t
- cls._G = _G
- setmetatable(cls, Object_mt)
- return cls
- end
- _G.new = new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement