lua-users home
lua-l archive

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


You're thinking method tables, but I'm talking about "instance tables". The instance table contains the component's local data, which includes a pointer to the C++ object instance associated with it. The event table of the index table is the method table. Get it? ;) You're thinking that the Lua table is just a list of C functions. I'm thinking that the Lua table could contain it's own data and functions, which work on top of the C functions.

I could still make the userdata the "main" object, with a custom "index" method that attempts to look up the object first in the method table, and then in the "local instance" table. Since most access will be methods anyway, it's probably not a big loss.

I think I'm cranky about this mostly because I had it all working (rolled my own event tables, basically), and what I thought was a minor version upgrade is turning out to be a complete rewrite of my scripting interface. Perhaps it would be better named Lua 5.0-work3.

Jason




Diego Nehab wrote:

The methods will have to be looked up in the table anyways. In Lua
4.1-work3, you can create a table with all the methods and set it as the
index field of the eventtable. The call

    userdatum:method(...)

will be translated to userdatum.method(userdatum, ...)
The dot will see its a userdatum and check the eventtable for the userdatum
and return the field 'method' of the index table.

This could be your C function that does whatever it wants with the pointer
it receives.
Even if you don't have eventtables, the method table could be passed as a
closure parameter to the userdatum index tag method.

I don't see how this is too bad. Maybe you need the references outside of C
functions called by lua methods.

Regards,
Diego.