I wish to implement a binding system for my OS's object model. The way I want this to work is to have a mechanism whereby I can wrap an arbitrary native object to turn it into a Lua object. I can inspect the native object to determine which interfaces it supports, and then generate the bindings for its methods on-the fly. The problem is figuring out how to do this efficiently. The naive way of doing it is rather inefficient. If I have a native object that implements interfaces A, B and C, each of which have 50 methods each, then importing that object will generate a Lua table containing 150 entries. Importing another object that implements interfaces B and C will cause a second table to be generated containing 100 entries. While I can share the function objects in the tables themselves, I'm still going to end up with big, bloaty Lua tables representing my objects. 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.) Can anyone suggest any other approaches I could look at? -- +- David Given --McQ-+ "...it's not that well-designed GUI's are rare, | dg@cowlark.com | it's just that the three-armed users GUI's are | (dg@tao-group.com) | designed for are rare." --- Mike Uhl on a.f.c +- www.cowlark.com --+
Attachment:
pgpkyQjrQw1QB.pgp
Description: PGP signature