[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Feature request: per-value uservalue
- From: Tim Hill <drtimhill@...>
- Date: Sun, 19 Mar 2017 20:11:33 -0700
> On Mar 19, 2017, at 12:03 PM, Xavier Wang <email@example.com> wrote:
> Some a long time ago Roberto make a joke about per-value metatable
> here, in a feature request raised by cloud wu.
> I found that's very exciting, but I missing the message that
> Roberto says that is just a joke. So sad, because this won't in Lua
> because it can not support __gc meta-method.
> __gc method may called when last value in Lua disappeared, if a
> metatable attach to value, it's no way to know how to free the gc
> objects. So metatable can not attach with value together.
> but, for now only full user data has the user value, setting/getting
> it using Lua API: lua_getuservalue()/lua_setuservalue(). So can we use
> the extra bits in value and make every value has uservalue? a integer
> is enough because we could put real value into a ref table. or make a
> internal array for the uservalue? When a value disappear we could just
> free the slot that this value use? or any ways to put a pointer in
> this field?
Other than tables or full userdata (which have per-value metatables), what do you need? I’m unclear on what use a metatable on a particular string, or a light userdata would have (why would it not be a full userdata in that case?).