lua-users home
lua-l archive

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

On Tue, Mar 1, 2011 at 7:52 AM, Thomas Harning Jr. <> wrote:
> On Mar 1, 2011 6:58 AM, "Tony Finch" <> wrote:
>> On Tue, 1 Mar 2011, Sylvain Fabre wrote:
>> > Le 01/03/2011 12:30, Tony Finch a écrit :
>> > >
>> > > Change the contents of the userdata itself so that it is no longer a
>> > > valid
>> > > instance of its original type.
>> >
>> > Sorry to come back on that, but how to do that in a C function (ie the
>> > send_message function, typically) ?
>> > I do not see how i can remove the variable from the C api.
>> You can only do it if you know the details of the particular object you
>> are dealling with. You can't do it in a generic way independent of what
>> is inside the userdata. But you need to know what's inside the userdata
>> to reconstruct it in the destination Lua state, so this restriction
>> should not be a problem.
>> It might be as simple as zeroing out the userdata and removing its
>> metatable.
> One mechanism that I've often used to implement a close method is to:
> * call gc method of userdata
> * remove metatable from object
> Now... this can be dangerous, depending on how the userdata works... it
> could be attached in a hierarchy depending on the GC and environment tables
> to link dependent userdata.
Reading through the thread, I realized I made a mistake assuming what
the goal was.

If you're working on moving data across VMs (either new process or
even new thread) you wouldn't necessarily want to GC the data...
almost certainly not, really.

If you are in full control of the userdata being transferred, you'd
want to transfer the contents and any related state (environment data,
etc)... this would be very specialized given each userdata... then you
could set the metatable to nil on the 'old' userdata location as a
mark of ownership transfer once successfully moved to the other vm.

Thomas Harning Jr.