[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How reliable is lua_topointer() ?
- From: Patrick Donnelly <batrick@...>
- Date: Tue, 11 Aug 2009 04:08:48 -0700
Hi Lawrie,
On Tue, Aug 11, 2009 at 2:56 AM, Lawrie Nichols<lawrien@gmail.com> wrote:
> I'm looking at using the pointer returned from lua_topointer() as an index
> into a weak-keyed table, but it's not obvious whether Lua might ever change
> these pointers during the execution of my scripts (ie whether a gc cycle
> might moving things around internally).
>
> I'm guessing that for userdata, ghe pointer cannot be changed (since Lua has
> no way of knowing the relevance of the data pointed to in the userdata), but
> I'm not so sure whether this would hold true for functions/tables.
>
> I've had a look at the PiL on lua_topointer(), and all that says is that the
> pointer cannot be used to to retrieve what was being pointed to.
>
> To be honest, from trying it out, there doesn't seem to be any issues, but
> I'd like to be sure.
I have not encountered an instance where lua_topointer is necessary.
You can instead use luaL_ref and luaL_unref for an integer reference
into the lua registry. Instead of pushing your light userdata with the
void pointer you stored, you can use this:
lua_rawgeti(L, LUA_REGISTRYINDEX, index);
--
-Patrick Donnelly
"Let all men know thee, but no man know thee thoroughly: Men freely
ford that see the shallows."
- Benjamin Franklin