userdata with automatic uservalue?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

userdata with automatic uservalue?

Marc Balmer
Hi

Is it possible that a userdata value that I create in C using lua_newuserdata() suddenly has a uservalue associated with it, i.e. without lua_setuservalue() being called from my code?

- Marc


smime.p7s (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: userdata with automatic uservalue?

Daurnimator


On 16 Jun 2016 22:13, "Marc Balmer" <[hidden email]> wrote:
>
> Hi
>
> Is it possible that a userdata value that I create in C using lua_newuserdata() suddenly has a uservalue associated with it, i.e. without lua_setuservalue() being called from my code?

Why would you ever need a non-union uservalue?
Generally you use metatables for per-type properties, uservalues for per-instance properties.

Reply | Threaded
Open this post in threaded view
|

Re: userdata with automatic uservalue?

Roberto Ierusalimschy
In reply to this post by Marc Balmer
> Is it possible that a userdata value that I create in C using
> lua_newuserdata() suddenly has a uservalue associated with it, i.e.
> without lua_setuservalue() being called from my code?

The only way to change the uservalue of a userdata is through an
explicit call to lua_setuservalue (in C) or debug.setuservalue (in Lua).

-- Roberto