From f77eb930ed5a72292d9986896d8b87eaea7f2e7e Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 28 May 2009 14:19:14 +0000 Subject: [PATCH] Add new simpler example to show dispatching of renamed functions --- boxedcpp/test.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/boxedcpp/test.cpp b/boxedcpp/test.cpp index ea173338..6ff7217e 100644 --- a/boxedcpp/test.cpp +++ b/boxedcpp/test.cpp @@ -34,6 +34,16 @@ void print(const std::string &s) std::cout << "Printed: " << s << std::endl; } +Boxed_Value named_func_call(BoxedCPP_System &ss, + const std::string &nametocall, const std::vector ¶ms) +{ + if (params.size() == 2) + { + return dispatch(ss.get_function(nametocall), params); + } else { + throw std::runtime_error("Invalid num params"); + } +} // A function that takes a dynamic list of params // and calls a bunch of conversion functions on them and @@ -152,5 +162,21 @@ int main() //Now, prove that the reference was successfully acquired //and we are able to peek into the boxed types dispatch(ss.get_function("show_message"), sos); + + + + + // Finally, we are going to register some named function aliases, for + // the fun of it + ss.register_function(boost::shared_ptr( + new Dynamic_Proxy_Function(boost::bind(&named_func_call, boost::ref(ss), "+", _1))), "add"); + + //Call our newly named "add" function (which in turn dispatches +) + + std::cout << "Result of add function: " << + Cast_Helper()(dispatch(ss.get_function("add"), Param_List_Builder() << 5 << 2)) + << std::endl; + + }