lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Shea Martin wrote:
> in my c function (registered as foo) I push two numbers on the stack. 
> In my script, I have this:
> 
> x,y = foo()
> 
> but only x gets a value, y is set to nil.  What am I doing 
> wrong here? 
> Roberto's book does not really talk about embedding.

Without the foo source code any answer would be just asumptions. Here is
my guess. You wrote:

int foo(lua_State* L)
{
   lua_pushnumber(L, 32);
   lua_pushnumber(L, 47);
   return 1;
}

Instead of 1 you should return the number of return values:

int foo(lua_State* L)
{
   lua_pushnumber(L, 32);
   lua_pushnumber(L, 47);
   return 2; /* <- Note the 2 instead of the 1 in the above example */
}

http://www.lua.org/manual/5.1/manual.html#lua_CFunction