[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: table question
- From: Romulo Bahiense <romulo@...>
- Date: Mon, 06 Mar 2006 14:02:09 -0300
Lee Smith wrote:
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
You are missing a << lua_settable(L, -3) >> here.
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");
Try to replace with this:
/* ... */
lua_pushvalue(L, -1); // push 1
lua_setglobal(L, "2ndtable"); // pop 1
lua_settable(L, -3);
tableIndex++;
lua_pushnumber(L, tableIndex);
lua_newtable(L); // push 1
/* ... */
--rb