【发布时间】:2018-11-27 23:01:12
【问题描述】:
我想知道C++中是否可以动态找出Lua函数的返回值个数。
例如,我可以像这样在 C++ 中的 Lua 函数中传递和返回值。
/* push functions and arguments */
lua_getglobal(L, "f"); /* function to be called */
lua_pushnumber(L, x); /* push 1st argument */
lua_pushnumber(L, y); /* push 2nd argument */
/* do the call (2 arguments, 1 result) */
if (lua_pcall(L, 2, 1, 0) != 0)
error(L, "error running function `f': %s", lua_tostring(L, -1));
/* do something with the result */
如您所见,它期望 Lua 函数返回 1 个值。因此,如果用户在 Lua 函数中返回多于(或少于)1 个值,它将无法正常工作。
是否有任何可能的解决方案可以提前检测 Lua 函数返回值的数量,以便我可以在 C++ 中动态处理返回值?
【问题讨论】:
-
多返回应该没问题吧?而且,ICYDK 每次调用都可能返回不同的号码。
标签: c++ function lua return-value