[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua C API can't be used from other languages without C wrappers
- From: albertmcchan <albertmcchan@...>
- Date: Sun, 18 Feb 2018 12:37:13 -0500
On Feb 18, 2018, at 11:54 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2018-02-18 18:37 GMT+02:00 Albert Chan <albertmcchan@yahoo.com>:
>> I have trouble using Lua C stack, even in C
>>
>> Say, I have a c function A that uses lua stack, that call another c function B
>> that also uses c lua stack. however, B did a lua_settop of 1, then return 1.
>>
>> Sine both c functions share the same stack, A loses everything except the result of B
>
> They do not. Every call generates a new stack frame, and no function
> can see further back than its own arguments, except those values that
> have been exported into its closure as upvalues. What you describe
> cannot happen.
>
you are right, if the call is from lua calling c-function.
If c-function A (from inside A) call B, however, we are sharing the same stack.
--> B removed all arguments except its result, did a lua_settop(L,1); return 1.
--> all stack arguments in A is GONE (except, result from B)
there is a blog about this problem: https://julien.danjou.info/blog/2011/why-not-lua
And this actualy happens to me recently. I had to fix B to leave the stack alone.
My question is, what if B is off-limit, how can it restore the stack from A side ?
more specifically, how to push userdata back to the stack ?