Skip to content

Instantly share code, notes, and snippets.

@od0x0
Created May 18, 2011 01:00
Show Gist options
  • Save od0x0/977800 to your computer and use it in GitHub Desktop.
Save od0x0/977800 to your computer and use it in GitHub Desktop.
My Lua Object System
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