From a758c86ba5993a46b0f8711832d9567978b108eb Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 14 Nov 2010 01:17:56 +0000 Subject: [PATCH] Add automatic unwrapping of Proxy_Function_Impl contained boost::function during functor() construction if possible. Task #110 --- .../chaiscript/dispatchkit/function_call_detail.hpp | 13 +++++++++++++ include/chaiscript/dispatchkit/proxy_functions.hpp | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 61de95e..1305c73 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -87,6 +87,19 @@ namespace chaiscript boost::function build_function_caller_helper(Ret (BOOST_PP_ENUM_PARAMS(n, Param)), const std::vector > &funcs) { + if (funcs.size() == 1) + { + boost::shared_ptr > pfi = + boost::dynamic_pointer_cast > + (funcs[0].second); + if (pfi) + { + return pfi->internal_function(); + } + // looks like this either wasn't a Proxy_Function_Impl or the types didn't match + // we cannot make any other guesses or assumptions really, so continuing + } + return boost::bind(&function_caller, funcs BOOST_PP_ENUM_TRAILING(n, curry, ~)); } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 82ac87c..272198a 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -457,6 +457,11 @@ namespace chaiscript return ""; } + boost::function internal_function() const + { + return m_f; + } + protected: virtual Boxed_Value do_call(const std::vector ¶ms) const {