[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_pushusertag and object ownership?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 16 Oct 2000 11:19:53 -0200
> I can't seem to find any information regarding ownership when using
> the lua_pushusertag C function.
Lua "owns" the pointer itself, but has no interaction at all with the
object pointed to. Lua never references the pointer, does not
garbage-collect it, nor uses it in any way. In fact, the "pointer" does not
need to be a valid pointer at all; you can call
«lua_pushuserdata((void *)3)» without any problem.
If the userdata has a garbage-collection tag method, this method is called
when the pointer itself is being "released" by Lua, that is, Lua is
assuring you that it does not have a copy of that pointer value anymore. It
is up to you to free your object when this tag method is called.