[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Anchor A double linked list in Lua?
- From: Xavier Wang <weasley.wx@...>
- Date: Mon, 14 Jul 2014 13:30:40 +0800
Hi list, I meet a problem :(
Now I have a double-linked list in C, and I want to write the binding
to export it to Lua. I hope Lua can manage it's lifetime, i.e.
- when you keep a reference to any element of list, the whole list
won't collect.
- when you can add/remove/split this list in lua.
- when you drop last reference to list element, the list will collect.
So, How can I do it? I don't want to set reference to element's
uservalue, because element usually don't have a uservalue table.
I'm using a weak value table on registry table, to save the map to
element and the next element pair in table. but to maintain this table
with add/remove/split is too difficult and need a lot of code.
another option is do not let lua manage the lifetime at all, when need
a node, Lua always new a userdata to hold pointer from C, and do
nothing when userdata collect, I can put userdata to a weak table to
cache it, but in this way, when userdata is collect, all lua-spec
information (uservalue, etc.) will lost :(
Anyone have some idea about this?
--
regards,
Xavier Wang.