lua-users home
lua-l archive

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


On Fri, 2006-04-21 at 11:13 +0100, David Given wrote:
> It very much depends on your OO system. Most Lua OO systems don't
> support any kind of 'super' syntax, because when an object is created
> they typically copy all methods from all superclasses into a single
> table in order to speed up method dispatch.

Mine rolls them up, but still supports a 'super' syntax, but it does so
with lots of closures and temporary tables.

Essentially each instance is a tuple of the class it is, the class this
instance acts as and the instance variables.
When a method is dispatched, 'self' is (K,K,I) but when parent(self) is
called, you get (K,parent(K),I) back. So parent(self):method() calls
'method' in parent(K) passing (K,K,I) in, such that self:overridden() is
the overridden version not the version in parent(K)

I'm not being terribly clear here but that's essentially what goes on.

You can find my class implementation at
http://bzr.digital-scurf.org/trees/dsilvers/aranha/lua/startup/10-Classes but that might be out of date and checking aranha out of bzr with:

bzr get http://bzr.digital-scurf.org/trees/managed/aranha

might be a better plan.

My class system does rely on aranha's version of lua though so it will
need (trivial) changes before it could run on an unpatched lua
interpreter.

D.

-- 
Daniel Silverstone                         http://www.digital-scurf.org/
PGP mail accepted and encouraged.            Key Id: 2BC8 4016 2068 7895