Created
May 18, 2011 01:00
-
-
Save od0x0/977800 to your computer and use it in GitHub Desktop.
My Lua Object System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object = {} | |
local ObjectMetatables = {} | |
function Object:new(...) | |
local clone = {} | |
local meta=ObjectMetatables[self] | |
if meta == nil then | |
meta = {__index=self} | |
ObjectMetatables[self] = meta | |
end | |
setmetatable(clone, meta) | |
if clone.init then | |
clone:init(...) | |
end | |
return clone | |
end | |
function Object:invokeMethodOnSuper(methodName, ...) | |
local method = getmetatable(self).__index[methodName] | |
return method(self, ...) | |
end | |
function Object:getInContextOfSuper(methodName) | |
local method = getmetatable(self).__index[methodName] | |
return function(...) return method(self, ...) end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment