lua-users home
lua-l archive

How does lua store data in a table?

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



Hi~

I use :

mydata["key1"] = "value1"
mydata["key2"] = "value2"


in a lua script.


and use :


lua_getfield(L, -1, "mydata");
if (lua_istable(L, -1)) {
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
if (lua_isstring(L, -1) && lua_isstring(L, -2)) {
const char *key, *val;
size_t key_len, val_len;

key = lua_tolstring(L, -2, &key_len);
val = lua_tolstring(L, -1, &val_len);

store_into_db("key", "value");
}
lua_pop(L, 1);
}
}


in c program to get data.


I've found that the pop order is different from the order I put data in.

How does lua store data in a table and is there any way to get data in the order of putting them in ?


thanks

AltStyle によって変換されたページ (->オリジナル) /