lua-users home
lua-l archive

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


>>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?
>
>Cause that would prevent using the stack during your api function.. And
>since the is no more begin/end block it would be impossible to
>push stuff on
>the stack to perform table functions ect....

It seems that this is only an issue if you use the stack and then don't
clean-up after yourself.  IE if you push something "temporary" onto the
stack, and then leave it there permanently.

Table functions should not be a problem because they pop from the stack any
values they use.  Nothing is left on the stack after the call.

The only problem case I can think of is where one Lua/C API reentrantly
calls another Lua function which returns values on the stack.  The outer
Lua/C API would then need to clean-up the stack, popping those values from
the inner API call before returning its own (unless it actually wanted to
return those values).

Is there something else I'm missing, because if this really is the only
reason for the new syntax, wouldn't it be better to shift the burden to the
less-frequent special case instead of requiring every API go through this
error-prone procedure?

ashley