lua-users home
lua-l archive

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


Eugen-Andrei Gavriloaie wrote:
> On Apr 9, 2008, at 6:04 PM, Jerome Vuarand wrote:
>> Jerome Vuarand wrote:
>>> You can't get the exact same result without tracking the number of
>>> "auto-assigned" keys yourself, but you can use the following to
>>> have a similar result: 
>> 
>> lua_push...(L, value);
>> lua_rawseti(L, -2, lua_objlen(L, -2) + 1); /* < note the +1 */
> 
> Tx for the response. But is some kind dangerous because the table
> might already contain a row with the same key. Am I right? 

No, lua_objlen(L, tindex) in C return is the same thing as #t in Lua,
which is a value that guarantees that t[#t+1] is nil, so the row is
never already used (as long as you don't do anything between the objlen
and the rawseti calls of course).