|
On Mar 1, 2011 6:58 AM, "Tony Finch" <dot@dotat.at> 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.