Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get(object)
- return getmetatable(object or {}) or {};
- end;
- function set(object, metatable)
- return setmetatable(object or {}, metatable or {});
- end;
- function mod(object, metatable, override)
- local omt = get(object);
- for mk, mv in pairs(omt) do
- if override then
- omt[mk] = mv; else
- omt[mk] = omt[mk] or mv; end;
- end; return set(object, omt);
- end;
- function clear(object)
- return set(object);
- end;
- function index(object, ...)
- local index = get(object).index or {};
- for ik, iv in ipairs({...}) do
- index[ik] = iv;
- end;
- local omt = {
- __index = function(object, key)
- local omt = get(object);
- for _, i in ipairs(omt.index or {}) do
- if i[key] then return i[key] end
- end;
- end;
- };
- omt.index = index;
- return mod(object, omt);
- end;
- function call(object, call)
- return mod(object, {
- __call = function(self, ...)
- return call(self, ...);
- end;
- });
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement