lua-users home
lua-l archive

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


>When a C function is called, its parameters are on the stack.
>When it returns, the results are also on the stack. To separate them, the
>function returns (in C) the number of results it is returning (in
>Lua).

Why is it necessary for the C API to return the number of results it pushed
onto the stack?  Wouldn?t it would be simpler and less error-prone for Lua
to infer that information directly from the stack?

IE, why can?t your example:

static int math_sin (lua_State *L) {
  lua_pushnumber(L, sin(TORAD(luaL_check_number(L, 1))));
  return 1;  /* <<<< Tells Lua it is returning one result */
}

be written as:

static void math_sin (lua_State *L) {
  lua_pushnumber(L, sin(TORAD(luaL_check_number(L, 1))));
}

It should be trivial for Lua to track the number of results pushed by the
API, yes?

ashley