sol2/examples/protect.cpp
ThePhD 6c40c559e3 prepare for new usertype
change how type T is gleaned from destructors and constructors in case of new syntax
add a hell of a lot more examples, update and clean documentation
2018-03-15 17:16:28 -04:00

28 lines
472 B
C++

#define SOL_CHECK_ARGUMENTS 1
#include <sol.hpp>
#include "assert.hpp"
int main () {
struct protect_me {
int gen(int x) {
return x;
}
};
sol::state lua;
lua.open_libraries(sol::lib::base);
lua.new_usertype<protect_me>("protect_me",
"gen", sol::protect( &protect_me::gen )
);
lua.script(R"__(
pm = protect_me.new()
value = pcall(pm.gen,"wrong argument")
)__");
bool value = lua["value"];
c_assert(!value);
return 0;
}