lua-users home
lua-l archive

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


When you write U.do_it (U:do_it() is equivalent to U.do_it(U)),
Right.  I actually want this behavior.  I'm binding C++ class
instances although in the example above I don't actually use the
instance.

you are
not using the userdata environment table but its metatable. More
specifically you are calling the userdata __index metamethod. In itself
it has nothing to do with environments.

To provide such behaviour to your userdata, you must have defined the
__index metamethod. To allow for method overrides you must implement the
__newindex metamethod.


I understand this is usally the case.  But I want per-instance custom
behavior whereas the metatable is for class behavior.  From the wiki
article:

"A userdata has both a metatable and an environment table. It seems
logical that the metatable contains information which is general to
the datatype of the userdata, while the environment table contains
information which is specific to the instance of the userdata."

What I don't undertand right now is how a userdata and its environment
table interact.

best,
wes