lua-users home
lua-l archive

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

On Feb 12, 2006, at 3:33 AM, PA wrote:
Your problem is right there: 'super' cannot be a straight attribute of your object for method dispatch purpose. It needs to be part of your object context instead.

I see! You're declaring a local variable 'super' in order for it to be captured in the closure of the init method. Tricky.

Which yet again points to the fact that 'super' type methods can't be written using first-class functions in a way that allows them to be used and re-shared. Pity.

Hrm...unless I went crazy-stupid and used global variables and wrapper functions. Something like...

function AKClass.prototype:addMethod( inName, inFunc )
	local theClass = self.class
	return function( ... )
		_super = theClass.superclass
		_methodName = inName
		return inFunc( unpack( arg ) )

function AKObject.prototype:super( ... )
	local theSuperMethod = _super[ _methodName ]
	if theSuperMethod then
		return theSuperMethod( unpack( arg ) )

Whee.... :)

Thanks for the discussion.

"When I am working on a problem I never think about beauty. I only think about how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong."
- R. Buckminster Fuller