Open tangjiands opened 4 months ago
The call to lua["funcBase"](&c);
returns a sol::protected_function_result
.
You can then check if this result was valid yourself like:
auto res = lua["funcBase"](&c);
if (!res.valid()) {
std::cout << "error occured!" << std::endl;
}
To make this call automatically print the error result you can call it from a protected function:
sol::protected_function protected_function(
lua["funcBase"], [](std::string message) {
std::cout << "error occurred : " << message << std::endl;
});
protected_function(&c);
class Base { public: virtual void print() { std::cout << "base print:" << x << endl; } private: int x; };
class A: public Base { public: void print() override { std::cout << "A print:" << y << endl; } private: int y; };
class C { public: void print() { std::cout << "B print:" << z << endl; } private: int z; }; void funcBase(Base* base) { return base->print(); }