lua-users home
lua-l archive

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

On Fri, Sep 23, 2005 at 11:26:03AM +0100, 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 use this for my binding to Gtk's GObject system and haven't found the
results of a C dispatcher to be slow.  Behind the scenes, maintain a
table for each class/interface and have the dispatcher look through the
tables in its search through the class hierarchy.  This avoids dealing
with non-interned strings, so all your potentially costly string
operations are handled with hashing.


Shannon Stewman         | Let us walk through the waning night,
Caught in a whirlpool,  | As dawn-rays tickle our toes, the dew soothes
A quartering act:       | Our blistered soles, and damp bones stir
Solitude or society?    | As crimson cracks under the blue-grey sky.