lua-users home
lua-l archive

Re: table question

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


This fails:
 lua_newtable(L); // push 1
 lua_pushnumber(L,tableIndex); // push 1
 lua_newtable(L); // push 1
 lua_pushstring(L, "item1"); // push 1
 lua_pushstring(L, "value (item 2)"); // push 1
 lua_settable(L, -3); // pop 2
 lua_pushstring(L, "item2"); // push 1
 lua_pushstring(L, "value (item 2)"); // push 1
 lua_settable(L, -3); // pop 2
 lua_pushvalue(L, -1); // push 1
 lua_setglobal(L, "2ndtable"); // pop 1
 tableIndex++;
 lua_pushnumber(L, tableIndex);
 lua_newtable(L); // push 1
 lua_pushstring(L, "item3"); // push 1
 lua_pushstring(L, "value (item 3)"); // push 1
 lua_settable(L, -3); // pop 2
 lua_pushstring(L, "item4"); // push 1
 lua_pushstring(L, "value (item 4)"); // push 1
 lua_settable(L, -3); // pop 2
 lua_pushvalue(L, -1); // push 1
 lua_setglobal(L, "3rdtable"); // pop 1
 lua_settable(L, -3); // push 2
 lua_setglobal(L, "testtable");
When being accessed like so:
 teststring = testtable[1]["item1"]
 print("teststring[item1]: " .. teststring )
 teststring = testtable[1]["item2"]
 print("teststring[item2]: " .. teststring)
 teststring = testtable[2]["item3"]
 print("teststring[item3]: " .. teststring )
 teststring = testtable[2]["item4"]
 print("teststring[item4]: " .. teststring)

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