I have a strange bug I came across while trying to help someone with an
issue with Sol. Lua says it can compile as C++. So, I tried to compile the
following with C++ and I get a strange error after throwing an error that
gets caught by the LUA_TRY macro and then returned:
// Compile Lua 5.3.3 as C++
// no extern "C" { ... }
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
int thrower(lua_State* L) {
throw 0;
}
int main() {
lua_State* L = luaL_newstate();
lua_pushcclosure(L, thrower, 0);
int top_before = lua_gettop(L);
int code = lua_pcallk(L, 0, 0, LUA_NOREF, 0, NULL);
int top_after = lua_gettop(L);
return 0;
}
`code == -1`, which isn't a valid return for `lua_pcallk`, and `top_before
== 1 `, and `top_after == 1` as well (the function is not cleaned off the
stack).
It seems like a bug in the Lua implementation.