lua-users home
lua-l archive

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



On Apr 9, 2008, at 8:35 PM, Jerome Vuarand wrote:

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

The table might have keys 1,2,3,55,34,22,"sdfds",etc. This table is returned by calling a lua function (is on the C++ stack). After doing some c++ processing I'd like to add more "anonymous" values (with no keys) to the table and pass it as a parameter to anoter lua function. So, I have no guarantee that the key is not in use. :(