lua-users home
lua-l archive

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


John Belmonte wrote:
> 
> It is not necessarily true that positive indexes don't change because the
> API allows any array elements to be inserted or deleted, changing the index
> of other values.

Only explicit on user request via lua_remove/insert.  And calling these
functions in a way that reorders already exported values is a bug.
Or what do you think if you - in C - export a pointer and later use that
memory for something else?

> The assumption I stated was that the object does not leave the scope of the
> Lua C function.  The lua_ref is not locked in that case, so the unref is not
> strictly needed although it makes things easier for the garbage collector.

No!  Each lua_ref must have a corresponding lua_unref.  It's right, the
object may be collected when not locked but the reference takes up space
in the ref-table.  The handle returned by lua_ref stays valid until you
call lua_unref.

> I haven't figured out any pattern in the API as far as why some functions
> take indexes and others only work with the stack top :(

Yeah.  It's confusing.  But I didn't see how it could be made better.
Afaics functions that are not supposed to consume an object take it by
index.

Ciao, ET.