lua-users home
lua-l archive

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


Thanks Jerome,

On 25/07/2007, at 5:07 PM, Jérôme Vuarand wrote:

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.

And I think certainly the one I try first, though I might just start by doing it all in Lua to get an idea of what it looks like (I'm particularly excited about using coroutines!)

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 ;-)

That's a good idea, though I think they probably won't be userdata, though at the moment, I'm just trying to get my head around how it might be done, so you never know.

Cheers,
Geoff