These are chat archives for ChaiScript/ChaiScript

20th
Apr 2018
Peter Taylor
@emersont1
Apr 20 2018 20:32
hi, i'm not sure what i'm doing wrong but when i try to add a function that is a lambda i get a error: no matching function for call to ‘fun<std::__cxx11::string(bool)>( ... ::<lambda(bool)>) would me having the scripting engine as a unique_ptr cause this?
Peter Taylor
@emersont1
Apr 20 2018 20:58
just from the cheatsheet example
Jason Turner
@lefticus
Apr 20 2018 21:03
you need to show us what you're actually trying to execute
Peter Taylor
@emersont1
Apr 20 2018 21:05

chai.add( chaiscript::fun<std::string (bool)>( [](bool type) { if (type) { return "x"; } else { return "y"; } }), "function_name");
Except for its to a unique pointer to the engine, not a stack instance. It works with class member functions, but lambdas give the no matching function error
Jason Turner
@lefticus
Apr 20 2018 21:19
and then how are you trying to call it? You're getting the error when you call it, not during the add, correct?
oh, I see that's a compile-time error you'r egetting
Peter Taylor
@emersont1
Apr 20 2018 21:21
Yeah, i should have explicitly said that
Jason Turner
@lefticus
Apr 20 2018 21:21
just do this instead:
chai.add( chaiscript::fun( [](bool type) -> std::string { if (type) { return "x"; } else { return "y"; } }), "function_name");
much cleaner
part of the problem is that you were trying to expose a function returning const char * as a function that returns std::string
Peter Taylor
@emersont1
Apr 20 2018 21:22
Okay thanks for your help