From: albertmcchan <albertmcchan@yahoo.com>
Date: February 18, 2018 5:24:07 PM EST
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Subject: Re: Lua C API can't be used from other languages without C wrappers
On Feb 18, 2018, at 5:06 PM, Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:"Albert" == Albert Chan <albertmcchan@yahoo.com> writes:Albert> I have trouble using Lua C stack, even in CAlbert> Say, I have a c function A that uses lua stack, that callAlbert> another c function B that also uses c lua stack. however, B didAlbert> a lua_settop of 1, then return 1.If A calls B _as a C function_, then B should not be using settop ormaking assumptions about the start of the lua stack.If you want B to be able to use the stack freely without affecting thecaller, then you just call it with lua_pushcfunction and lua_call ratherthan directly.--Andrew.
confession time: i wrote B :-(
At the time, I HAD to "clean" the stack and return 1
(i were not sure which side the 1 referred ... stack 1 ? stack -1 ?)
Now, I know return 1 will be enough (if result is at top of stack)
B function work perfectly, however, when call from lua.
I only noticed the bug when it were called from A, another c-function.