2007/7/24, Geoff Leyland <geoff_leyland@fastmail.fm>:
One way I can imagine doing this at the moment is to create a table
in the registry and store the lua functions at indexes in that table,
and then store those indexes in the priority_queue. That way, Lua is
aware that I'm interested in those objects, and I have a way of
keeping hold of them. Popping to top off the priority queue will
also mean removing an element from the table, which I imagine will be
a little inefficient. Possibly more than I'd like, but I'll have to
see.
I think this is the right solution.
If your Lua objects are userdata instead of functions or tables, you
can store them directly in the registry, with the userdata itself as
value, and a lightuserdata pointing to the full userdata as the key.
You can then store that lightuserdata in your priority_queue. This
removes the need for an intermediate table, and it may be easier to
manage than integers.
This means that you will use the hashmap part of the table instead of
the array part, but since your data structure is a queue it may end up
being a sparse array and anyway use the hashmap of the table.
That's just ideas to widen your perspectives, do not take it as an
expert's advice ;-)