[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: A few Wild and Wooly Proposals, while we're here (was Re: Feature request: userdata slice)
- From: William Ahern <william@...>
- Date: Thu, 20 Aug 2015 20:06:40 -0700
On Fri, Aug 21, 2015 at 04:39:31AM +0200, Philipp Janda wrote:
> Am 21.08.2015 um 04:18 schröbte Sean Conner:
>
> >
> >1) Allow unique metatables for lightuserdata, that also respect __gc.
>
> lightuserdata is a value type. `__gc` doesn't work well with value types ...
>
> lua_pushlightuserdata( L, 0x1234 );
> luaL_getmetatable( L, "metatablewithgc" );
> lua_setmetatable( L, -2 );
> lua_pushvalue( L, -1 ); /* duplicate lightuserdata */
> lua_pop( L, 2 );
> /* should the __gc method really run twice now? */
>
Yeah. And regardless of should, it _won't_. To be garbage collectable a
value needs many more members for the GC algorithm, and it has to be
allocated separately, with reference semantics rather than value semantics.
Full userdata, closures, and tables are all represented as GCObjects. For
__gc to be triggered when a lightuservalue values goes away, one would need
to make it a GCObject, effectively making it identical to full userdata.
- References:
- Re: Feature request: userdata slice, Dirk Laurie
- Re: Feature request: userdata slice, 云风 Cloud Wu
- Re: Feature request: userdata slice, Dirk Laurie
- Re: Feature request: userdata slice, Dirk Laurie
- Re: Feature request: userdata slice, Tim Hill
- Re: Feature request: userdata slice, William Ahern
- Re: Feature request: userdata slice, Roberto Ierusalimschy
- Re: Feature request: userdata slice, William Ahern
- A few Wild and Wooly Proposals, while we're here (was Re: Feature request: userdata slice), Sean Conner
- Re: A few Wild and Wooly Proposals, while we're here (was Re: Feature request: userdata slice), Philipp Janda