0
我可以替換表格嗎?例如我不能得到這個工作:C:可以替換表格
lua_createtable(L,0,0);
lua_replace(L,2); // is the 2nd parameter of a function call
我可以替換表格嗎?例如我不能得到這個工作:C:可以替換表格
lua_createtable(L,0,0);
lua_replace(L,2); // is the 2nd parameter of a function call
你可以與任何在頂部的指定索引lua_replace
任何LUA值。這裏有一個簡單的單元測試是把你的新的空表,並將其移動到位置2,用無論發生什麼事情在那裏:
int test_replace(lua_State *L)
{
lua_getglobal(L, "_VERSION");
lua_getglobal(L, "os");
lua_getglobal(L, "os");
printstack(L);
lua_createtable(L, 0, 0);
lua_replace(L, 2);
printstack(L);
return 0;
}
簡單printstack
展現什麼是LUA堆棧:
const char *lprint =
"function lprint(...)"
" local _, arg2 = ..."
" print(...)"
" return ..."
" end";
int printstack(lua_State *L)
{
const int argc = lua_gettop(L);
lua_getglobal(L, "lprint");
lua_insert(L, 1);
lua_call(L, argc, argc);
return argc;
}
現在,如果您運行test_replace
,例如。
luaL_dostring(L, lprint);
lua_pushcfunction(L, test_replace);
lua_call(L, 0, 0);
可能的輸出:
的Lua 5.2表:00431A10表:00431A10
的Lua 5.2表:00431DD0表:00431A10
如果在你的問題的代碼片段不工作,那麼你在周圍的環境中做了錯誤的事情,你沒有顯示。