2010-11-18 31 views

回答

7

manual說:

void lua_setfield (lua_State *L, int index, const char *k); 

是否相當於t[k] = v,其中t是在給定的有效索引值,並v是在堆棧的頂部的值。

該函數從堆棧中彈出值。

所以,更準確地說:將任何你想添加到堆棧上的東西,然後調用lua_setfield。例如:

lua_pushnumber(L, 42); 
lua_setfield(L, -2, "answer_to_life_universe_and_rest") 

此插入場「answer_to_life ......」與價值42到表中。

+0

它引發了一個錯誤... – 2010-11-18 23:58:17

+1

'lua_pushnumber(L,42);' – lhf 2010-11-19 00:55:58

+0

nvm:P我把這些行混合起來 – 2010-11-19 04:13:55