sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

Some Lua errors from C++ functions are caught incorrectly

Open roman-orekhov opened this issue 2 years ago • 0 comments

#include <cstdint>
#include <sol/sol.hpp>

int main() {
  sol::state lua;

  //lua.set_function("main_impl", [](sol::this_state s) {
  //  sol::state_view lua(s);
    lua["a"]       = "blah";
    std::int64_t a = lua["a"]; // error here
  //});
  //lua.script("main_impl()");
}

This produces expected error: [sol2] An error occurred and panic has been invoked: stack index -1, expected number, received string: not a numeric type that fits exactly an integer (number maybe has significant decimals)

But when the lines are uncommented, the stack frame with the error message gets lost and last item pushed to stack, if it's a string, is considered as an error message: [sol2] An error occurred and has been passed to an error handler: sol: runtime error: blah

roman-orekhov avatar Jul 07 '23 11:07 roman-orekhov