lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Feb 12, 2006, at 6:05 AM, Gavin Kistner wrote:
function AKClass.prototype:addMethod( inName, inFunc )
local theClass = self.class
return function( ... )
_super = theClass.superclass
_methodName = inName
return inFunc( unpack( arg ) )
end
end

Bah, I forgot to assign that function to anything, AND I'd need to save/restore those variables for stack-based calls/exits.

Closer to:

function AKClass.prototype:addMethod( inName, inFunc )
local theClass = self.class
self[ inName ] = function( ... )
local oldSuper, _super = _super, theClass.superClass
local oldMethodName, _methodName = _methodName, inName
local theReturnValue = inFunc( unpack( arg ) )
_super, _methodName = oldSuper, oldmethodName
return theReturnValue
end
return self[ inName ]
end


Definitely not something I'd consider implementing if either speed or memory were tight, but a fun mental exercise in pure hackery, nonetheless.