lua-users home
lua-l archive

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


2011/4/7 Timothée VERROUIL <dreamothee@hotmail.com>:
> Hi,
>
> I don't get any error.
> When I write : local toto = myObject.myAttribute ; Lua consider
> myObject.myAttribute as a function
> and when I print the value of toto, it's nil :(


If you want both methods and attribute-like access to userdata, you
have to explicitly distinguish between the two in your userdata
design.  __index for userdata typically returns a function, but if in
your __index method, you detect that the key being accessed is
actually an attribute, you can instead call that function and return
its result.  In my userdata, I keep separate tables of settable and
gettable attributes and check these in __index/__newindex to get
attribute-like access.

wes