I use Sol2 in my project and I have some trouble running C++ functions from Lua. First of all, I binded some functions to lua via sol::set_function(). For example:
I have this function:
void PrintInt(int value){
std::cout << "Something" << std::endl;
}
In my main I do this:
int main() {
sol::state state;
state.set_function("PrintInt", &PrintInt);
}
Now if I call function in Lua it works fine. But I have some situations in my game code which can produce some unexpected calls, like this one in Lua:
PrintInt(nil)
All code here is pseudocode, so doesn't matter how this happen. It can be, because Lua scripts are written by gamer. So question is how can I avoid this to happen? I don't want to force player write checks and etc.
I have checks in C++ at load and running script, but it doesn't provide me any error. I use sol::protected_function_result to check for errors.
I tried to use sol::optional, but I got "Cannot find class '', to resolve delegate 'optional'".