sol2/tests/regression_tests/1011/source/1011 - release mode crash MSVC.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

2020-08-13 22:42:37 +08:00
#define SOL_NO_EXCEPTIONS 1
#define SOL_SAFE_REFERENCES 1
#define SOL_SAFE_USERTYPE 1
#define SOL_SAFE_FUNCTION_CALLS 1
#define SOL_SAFE_FUNCTION 1
#define SOL_SAFE_NUMERICS 1
#define SOL_SAFE_GETTER 1
#include <sol/sol.hpp>
#include <iostream>
#if THIS_IS_BUSTED
2020-08-13 22:42:37 +08:00
std::string testFunc(std::string str) {
std::cout << "in testFunc" << std::endl;
2020-08-13 22:42:37 +08:00
return std::string("hello ") + str;
}
int main() {
sol::state lua;
lua.open_libraries(sol::lib::base);
lua["testFunc"] = &testFunc;
lua.script(R"(
function f ()
-- call a function with wrong arguments
-- to trigger lua_error
print("calling function")
2020-08-13 22:42:37 +08:00
testFunc()
end
)");
std::cout << "bark" << std::endl;
2020-08-13 22:42:37 +08:00
sol::protected_function f(lua["f"]);
std::cout << "baa" << std::endl;
2020-08-13 22:42:37 +08:00
sol::protected_function_result result = f();
std::cout << "meow" << std::endl;
2020-08-13 22:42:37 +08:00
if (result.valid()) {
// Call succeeded
std::cout << "call succeeded" << std::endl;
}
else {
// Call failed
sol::error err = result;
std::string what = err.what();
std::cout << "call failed, sol::error::what() is " << what << std::endl;
}
}
#else
int main(int, char*[]) {
return 0;
}
#endif