lua-users home
lua-l archive

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


On Feb 11, 2006, at 7:39 PM, David Given wrote:
On Sunday 12 February 2006 00:41, Gavin Kistner wrote:
[...]
I'm confused what you mean by this. Could you elaborate?

It's the standard Python trick (which suffers from this same problem). When you define a class, you define symbol local to the class that points at your class' superclass (does that sentence actually make sense)? It means that you can use clearer terminology when you call methods, and if you want to change your class hierarchy you only need to modify one thing rather than hunting
down every place where you call your superclass.

The above code is an extension of this concept where PA's defining a symbol that points at the *current* class. Interesting idea, and possibly one I'll
think about adopting.

I am still not sure I understand how this works in a three-layer case like the one I posted before. Here's what I *think* was being suggested, in a hard-coded way.


Rectangle = {
	initialize = function( obj )
		print( "Rectangle's initializer, yay!" )
	end
}

Square = {
	initialize = function( obj )
		print( "Square's initializer" )
		obj.super.initialize( obj )
	end
}

UnitSquare = {
	initialize = function( obj )
		print( "UnitSquare's initializer" )
		obj.super.initialize( obj )
	end
}

mySquare = {
	class = Square,
	super = Rectangle
}

Square.initialize( mySquare )
--> Square's initializer
--> Rectangle's initializer, yay!


myUnitSquare = {
	class = UnitSquare,
	super = Square
}

UnitSquare.initialize( myUnitSquare )

--> UnitSquare's initializer
--> Square's initializer
--> Square's initializer
--> Square's initializer
--> Square's initializer
(4000 or so more)

lua: stack overflow
stack traceback:
	[C]: in function `print'
	/Users/gkistner/Desktop/tmp.lua:9: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	...
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:10: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:17: in function `initialize'
	/Users/gkistner/Desktop/tmp.lua:36: in main chunk
	[C]: ?