On 2005-03-15 23:02 -0500, Zachary P. Landau wrote:
>
> Hello,
>
> I'm not sure if you want libextl questions on the ion3 mailing list or
> not. If so, feel free to reply to the list instead.
>
> I'm using libextl for the ion keybindings editor, as you suggested. I'm
> finding it intuitive for the most part. I just have a couple of things
> I can't quite figure out.
>
> The first one has to do with extl_ref_table. I have some lua calls that
> look similar to this:
>
> function kpress(kcb, cmd, guard)
> return ionconf.add_binding {
> action="kpress",
> kcb=kcb,
> cmd=cmd,
> guard=guard
> }
> end
It seems unnecessary to call the C side at this point...
> This is called a bunch of times by loading in a cfg_bindings.lua.
>
> Now, inside of ionconf.add_binding I want to save a reference to the
> given table so I can get to it later. So here is some test code:
>
> EXTL_EXPORT
> ExtlTab ionconf_add_binding(ExtlTab t)
> {
> printf("ID: %i\n, extl_ref_table(t));
> }
>
> But the IDs being returned aren't unique. Most of the IDs returned
> alternate between 8 and 7.
>
> Do you know why my ID numbers aren't unique? I plan to use the IDs so
> that when someone deletes or changes an item in the GUI, I can modify
> the correct lua table. But obviously these numbers being returned
> aren't correct for doing that.
You may have expected extl_ref_table to increment a reference counter, but
this is not. There are no referene counters. Every extl_ref_table (or
extl_ref_fn) call allocates a free entry in the table LUA_REGISTRYINDEX to
store a reference to the object in question. The returned value is this
index. extl_unref_table (extl_unref_fn) call sets this entry to nil. These
references in the registry simply prevent the garbage collector from
reclaiming the object if no Lua-side code (indirectly) references it.
It is possible to add an extl_table_eq call, but I don't think that this
is necessary.
> The only question is much simplier. Is there a simple method for
> accessing global variables through libextl? I only see a few references
> to LUA_GLOBALSINDEX and none of them seem to be for doing this.
Libextl used to have extl_globals() returning a reference to the globals
table, but I removed it for portability of the API to other languages.
--
Tuomo