Call a method with default parameters


myFunction (int a, int b = 5) {

How can I call this method from Chaiscript omitting the second parameter?


There’s no way to detect default parameters, but you can kind of emulate it from the C++ side.

// cpp

void myFunction(int a, int b = 5) { }

// later

chai.add(chaiscript::fun(&myFunction), "myFunction"); // both params accepted
chai.add(chaiscript::fun([](int a) { return myFunction(a); }), "myFunction"); // use lambda to default the second param




That’s awesome, thanks.
It helps when dealing with existing methods to be able to do this sort of thing - and using a lambda is a pretty elegant solution!