lua-users home
lua-l archive

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

>is there any chance to get tag methods for reading
>and assigning from/to userdata/usertypes?

What exactly did you have in mind?

>That would be a really great improvement if used
>often, f.i. if you export a C++ class as a table
>in lua and want some members to be accessable
>you have to override get/settable, lookup the
>names for each access etc. with set/get tag
>methods the additional lookup won't be necessary.

The natural way to do this in Lua is to have a table proxy in Lua for the
C object. This table has tag methods that redirect unknown fields to C.
In other words, for getting values from both C and Lua, it's enough to
set an "index" tag method for the table. Fields that are present in the Lua
table will be handled transparently; no need for setting a "gettable" method.
Unfortunately, there's no "setindex" tag method to replace the "settable"
method for setting fields. Perhaps "setindex" would be a candidate for a new
tag method.