When I use lua_call
or lua_pcall
, in addition to running the lua chunk, it also pops the chunk from the stack. Is there any way I can run the chunk while still keeping the chunk on the stack?
Asked
Active
Viewed 416 times
2

Ace shinigami
- 1,374
- 2
- 12
- 25
-
3You can make additional copy of chunk with `lua_pushvalue` or `lua_copy` – Egor Skriptunoff Nov 27 '17 at 03:39
-
instead of making a copy, can I just not ever remove it from the stack? – Ace shinigami Nov 27 '17 at 03:49
-
I guess you cannot. This is how `lua_call` works. – Egor Skriptunoff Nov 27 '17 at 04:04
-
is there any reason why, it seems odd to bake in this extra step? Sorry if I'm missing something obvious/fundimental, I'm new to the lua-api so it's possible I'm being a dumb noob. – Ace shinigami Nov 27 '17 at 04:07
-
1Probably, this behavior of `lua_call` was chosen by Lua authors to facilitate calculation of chained functions such as `local x = f(g())`, otherwise you would have to manually move all values returned by `g()` in the Lua API stack. – Egor Skriptunoff Nov 27 '17 at 14:42