[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Debug API and return values
- From: Kevin Senn <kevin.senn@...>
- Date: Thu, 19 May 2011 16:04:52 -0400
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"?