[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Replaced print function return stack getting emptied
- From: Bruce Wheaton <bruce@...>
- Date: Sun, 6 May 2012 20:44:39 -0700
On May 6, 2012, at 1:20 PM, Kevin Martin wrote:
> On 6 May 2012, at 17:52, Bruce Wheaton wrote:
>> It gets called and works fine - leave the stack with the original stack, plus a function and my new results, and returns the number of results. It works with 1 or more results.
> From the lua 5.2 manual:
> Whenever Lua calls C, the called function gets a new stack, which is independent of previous stacks and of stacks of C functions that are still active. This stack initially contains any arguments to the C function and it is where the C function pushes its results to be returned to the caller (see lua_CFunction).
OK…. so. I have a C function, that happens to replace print. It pushes a string onto the stack for each argument to the print function, then returns the number of items it added to the stack.
A dump stack shows the new items and the correct count.
But I then *thought* I would get those items on a stack after the lua state has processed the command. Apparently no, although a 'return 1' does pass something back on the stack.
Confusing to me. But I'm just starting my embedding adventures.