Eon*_*nil 13 lua runtime dynamic count return-value
luaL_loadstring(L, "return 3, 4, 5");
int R = lua_pcall(L, 0, 3, 0);
Run Code Online (Sandbox Code Playgroud)
Lua可以返回多个值.但是目前我必须硬编码返回值的计数.我可以动态地知道运行时的计数吗?
Joh*_*eek 17
是.
int top = lua_gettop(L);
luaL_loadstring(L, "return 3, 4, 5");
int R = lua_pcall(L, 0, LUA_MULTRET, 0);
int nresults = lua_gettop(L) - top;
Run Code Online (Sandbox Code Playgroud)
您使用LUA_MULTRET,然后用来lua_gettop计算调用前后的堆栈顶部.