[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Debug API and return values
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 4 Jun 2011 15:25:42 -0300
> The documentation says, for the return hook, "You have no access to
> the values to be returned by the function." But when I examine the
> stack in the return hook, I can see the return values there. And for
> Lua functions (not necessarily C functions, though), it seems easy
> enough to figure out which items exactly are the return values. It
> seems they are the last N items in the stack, where N is equal to the
> size of stack minus the number of input parameters the function has
> (which there are other means of detecting).
>
> We also have the means to determine when a tail return is taking
> place, and with similar arithmetic (using the tail call's "input
> parameter count" rather than the "current function's") we can figure
> out the return values in this case too.
>
> The arithmetic also works out for vararg functions.
>
> So my question is, is it unsafe to rely on this behaviour, because
> it's officially documented that you "can't do it"?
Probably the manual should say "there is no standard way to access
the values to be returned". And yes, it is unsafe to rely on this
behavior. (For instance, a function like 'function (a,b,c) return a end'
does not have its return value at the top of the stack.)
-- Roberto