I want to pop / clean the Lua call stack while within a C function called from Lua. Is this possible?
Background:
I want my C library and its extension scripts to use the same test framework. (I am aware various unit testing tools exist for Lua. I don't care; I want one report) I'm wrapping CUnit in a thin layer of Lua. CUnit provides a choice of fatal and non-fatal test assertions. Fatal assertions cause an immediate longjmp out of the test and back into the framework runner. This seems like it would do bad things to the Lua VM if I did not clean the stack first.
The stack will probably look something like:
#0. C: assert_wrapper_fcn(test, fatal)
#1. Lua: assert_fcn(bool)
#2. Lua: test_fcn()
#3. C: runner(&test_fcn)
I want to clean up everything between #0 and #3. I know the method signatures of test_fcn() and assert_fcn(bool), but that's it.
To empty the stack is really easy. Just use lua_settop with 0 as argument.
lua_settop(L, 0);
Not sure I'm understanding the question quite right... but to clear out Lua's stack:
int stackSize = lua_gettop(L);
lua_pop(L, stackSize);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With