lua-users home
lua-l archive

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


Hi,

> The table *is* the script interface to the object. The table does 
> contain a reference to the userdata, in fact it has the *only* 
> reference to the userdata, so I must rely on the Lua table to 
> determine the lifespan of the object.
> 
> I could use the userdata as the object interface in Lua, but then 
> every access would have to go look up the associated table, which 
> seems worse than reimplementing lua_ref(0) myself.

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.