我在C中創建了一個Lua表,但我不確定如何將該表推到堆棧的頂部,因此我可以將它傳遞給一個Lua函數。推一個Lua表
有誰知道如何做到這一點?
這是我當前的代碼:
lua_createtable(state, libraries.size(), 0);
int table_index = lua_gettop(state);
for (int i = 0; i < libraries.size(); i++)
{
lua_pushstring(state, libraries[i].c_str());
lua_rawseti(state, table_index, i + 1);
}
lua_settable(state, -3);
[ Push other things ]
[ Call function ]
我會如何將兩個不同的表推送到相同的功能? – 2010-10-21 14:42:49
lua_pcall中的第二個參數是傳遞給函數的參數數量,所以您可以將兩個表都推入堆棧,然後將pcall更改爲lua_pcall(L,2,0,0); – 2010-10-21 16:01:19