Handle the ReturnVal exception at the eval_function level so that functions passed back to C++ land have their return values handled properly
This commit is contained in:
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
boost::function<std::string (const std::string&, const std::string &)> f =
|
boost::function<std::string (const std::string&, const std::string &)> f =
|
||||||
dispatchkit::build_functor<std::string (const std::string &, const std::string &)>
|
dispatchkit::build_functor<std::string (const std::string &, const std::string &)>
|
||||||
(chai, "function(x, y) { x + y }");
|
(chai, "function(x, y) { return x + y }");
|
||||||
|
|
||||||
std::cout << "Functor call: " << f("Hello", " World") << std::endl;
|
std::cout << "Functor call: " << f("Hello", " World") << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,14 @@ namespace chaiscript
|
|||||||
ss.add_object(param_names[i], vals[i]);
|
ss.add_object(param_names[i], vals[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatchkit::Boxed_Value retval = eval_token(ss, node);
|
dispatchkit::Boxed_Value retval;
|
||||||
|
|
||||||
|
try {
|
||||||
|
retval = eval_token(ss, node);
|
||||||
|
} catch (const ReturnValue &rv) {
|
||||||
|
retval = rv.retval;
|
||||||
|
}
|
||||||
|
|
||||||
ss.pop_scope();
|
ss.pop_scope();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
cb_handler.add_callbacks( function() { "First"; }, function (x) { x * 1.1; } );
|
cb_handler.add_callbacks( function() { "First"; }, function (x) { x * 1.1; } );
|
||||||
cb_handler.add_callbacks( function() { "TimesThree"; }, function(x) { x * 3.0} );
|
cb_handler.add_callbacks( function() { "TimesThree"; }, function(x) { return x * 3.0} );
|
||||||
cb_handler.add_callbacks( function() { "DivOnePtTwo"; }, function (x) { x / 1.2; } );
|
cb_handler.add_callbacks( function() { "DivOnePtTwo"; }, function (x) { x / 1.2; } );
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user