lua-users home
lua-l archive

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


On Tue, Aug 11, 2009 at 10:17 AM, Lawrie Nichols<lawrien@gmail.com> wrote:
> Hi Patrick
>
> thanks, but it's really the pointers I'm looking for. Firstly, I need to be
> able to store UD pointers in a weak-keyed table so that I can look it up
> based on a pointer coming into a C callback, and I need to be sure that Lua
> is going to return the same pointer for the given UD each time.
>
> Secondly, I wanted to know whether storing a pointer to a function in a
> given table could be used later to determine whether the function had been
> updated in that table (since __nexindex only notifies of new items in a
> table, it's quite awkward to figure out if a function has been updated, and
> using UDs as proxies is real slow...). Obviously, if the function pointer
> might be updated by Lua, this wouldn't work, but as it is I think I'm going
> to try using it :-)
>
> Finally, not too sure if refs work in weak-referenced tables....
Pointer's wouldn't work either (if I have that right)... assuming
you're pushing them as lightuserdata, my guess is that they behave
just like strings and numbers would, since they are a 'primitive'
type.  Also... the GC has no clue that a lightuserdata is equivalent
to a given userdata, table, function when iterating for cleanup, so
the GC wouldn't even be able to mark the two items as the same....
now.. that's assuming weak-keyed...

As for weak-valued, then both lightuserdata and luaL_ref and the like
would work correctly (I think) .. just that there'd be holes showing
up over time.  If the holes can be re-filled by new data and
re-returned through luaL_ref ... I don't know.... implementation
defined.


-- 
Thomas Harning Jr.