On Mar 14, 2007, at 6:06 AM, Samuel Chi wrote:
example for lua_call in lua-manual.html :
Lua code:
a = f("how", t.x, 14)
C:
int level = lua_gettop(L);
lua_getfield(L, LUA_GLOBALSINDEX, "f"); /* function to be called */
lua_pushstring(L, "how"); /* 1st argument */
lua_getfield(L, LUA_GLOBALSINDEX, "t"); /* table to be indexed */
lua_getfield(L, -1, "x"); /* push result of t.x (2nd arg) */
lua_remove(L, -2); /* remove 't' from the stack */
lua_pushinteger(L, 14); /* 3rd argument */
lua_call(L, 3, 1); /* call function with 3 arguments and1 result */
lua_setfield(L, LUA_GLOBALSINDEX, "a"); /* set global variable 'a' */
----->
lua_call(L, 3, LUA_MULTRET);
// how to get count of result?
int nresults = lua_gettop(L) - level;