[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Object binding comments wanted
- From: "Adam D. Moss" <adam@...>
- Date: Fri, 23 Sep 2005 12:35:27 +0100
Hi!
David Given wrote:
An alternative system is to have a seperate table that represents each
interface, and have the __index metatable entry for the object itself look up
each interface in turn. This would be nicely memory-efficient, because all
the object table needs to store is the list of supported interfaces, but will
require dropping into Lua code to look up every method call on the object,
which will be slow. (Rewriting the dispatcher in C would help but I'm still
not terribly happy.)
I don't really know what you mean about dropping into Lua to look up
every method call. I don't imagine that every combination of interfaces
is actually used by objects - make a table which is shared by each
'class', which is what you really have there, not one big table shared
by every class which is then filtered per-object. Then no dispatcher.
This would be the usual way people implement classes in Lua.
Can anyone suggest any other approaches I could look at?
As well as a more straightforward approach such as above, I do
also recommend trying-before-optimizing. Lots of details which
it's easy to assume will be too slow, just get lost in the noise
in real benchmarking. That said, method invokation is an important
case, but without the dispatcher madness it's just a metatable
lookup and a function call. Note that if a __index value is a
table instead of a function, Lua will handle a lookup into that
table itself instead of you having to write any sort of trivial
dispatcher for that case.
cheers,
--adam
--
Adam D. Moss - adam@gimp.org