[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Moving towards a class system package proposal
- From: PA <petite.abeille@...>
- Date: Sat, 22 Jan 2005 23:02:17 +0100
On Jan 22, 2005, at 21:30, Mark Hamburg wrote:
where objc_super is defined as "including the instance of the class
that is
to receive the message and the superclass at which to start searching
for
the method implementation".
Still waiting for my Lua book to show up... so feel free to slap me on
the head if I'm talking nonsense :)
Looking at Chapter 16.2 - Inheritance [1] in Programming in Lua,
Roberto defines its constructor method like this:
function Account:new (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
What about redefining it along the following lines for the Lua root
class, called "LUObject" for the sake of argument:
function LUObject:new ( anInstance )
anInstance.super = self
setmetatable( anInstance, self)
self.__index = self
return anInstance
end
(Not quite sure about the exact syntax and parameters order here, but
hopefully you get the gist of it :)
When subclassing LUObject, one calls the super class "new" factory
method, passing itself as an instance:
function MySubclass:new ()
return LuaObject( self )
end
Now there is an explicit class hierarchy between the two objects.
Assuming an existing "description" method in the superclass one would
like to extend, one could now invoke it like this:
function MySubclass:description ()
super:description()
print "my very own description as well"
end
Does this make any kind of sense?!?
Thanks!
Cheers
--
PA
http://alt.textdrive.com/
[1] http://www.lua.org/pil/16.2.html