diff --git a/include/chaiscript/dispatchkit/callable_traits.hpp b/include/chaiscript/dispatchkit/callable_traits.hpp index 49978d2..e1fe612 100644 --- a/include/chaiscript/dispatchkit/callable_traits.hpp +++ b/include/chaiscript/dispatchkit/callable_traits.hpp @@ -7,9 +7,20 @@ #ifndef CHAISCRIPT_CALLABLE_TRAITS_HPP_ #define CHAISCRIPT_CALLABLE_TRAITS_HPP_ +#include + namespace chaiscript { namespace dispatch { namespace detail { + template + struct Constructor + { + template + std::shared_ptr operator()(Inner&& ... inner) const { + return std::make_shared(std::forward(inner)...); + } + }; + template struct Const_Caller { diff --git a/include/chaiscript/dispatchkit/function_call_detail.hpp b/include/chaiscript/dispatchkit/function_call_detail.hpp index 9410d15..fb6b5fc 100644 --- a/include/chaiscript/dispatchkit/function_call_detail.hpp +++ b/include/chaiscript/dispatchkit/function_call_detail.hpp @@ -95,6 +95,7 @@ namespace chaiscript template std::function build_function_caller_helper(Ret (Params...), const std::vector &funcs, const Type_Conversions *t_conversions) { + /* if (funcs.size() == 1) { std::shared_ptr> pfi = @@ -108,6 +109,7 @@ namespace chaiscript // 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 std::function(Build_Function_Caller_Helper(funcs, t_conversions?*t_conversions:Type_Conversions())); } diff --git a/include/chaiscript/dispatchkit/handle_return.hpp b/include/chaiscript/dispatchkit/handle_return.hpp index d028e85..d5bdb9d 100644 --- a/include/chaiscript/dispatchkit/handle_return.hpp +++ b/include/chaiscript/dispatchkit/handle_return.hpp @@ -23,7 +23,7 @@ namespace chaiscript { namespace dispatch { - template class Proxy_Function_Impl; + template class Proxy_Function_Callable_Impl; template class Assignable_Proxy_Function_Impl; namespace detail @@ -54,7 +54,7 @@ namespace chaiscript { static Boxed_Value handle(const std::function &f) { return Boxed_Value( - chaiscript::make_shared>(f) + chaiscript::make_shared>>(f) ); } }; @@ -64,7 +64,7 @@ namespace chaiscript { static Boxed_Value handle(const std::function &f) { return Boxed_Value( - chaiscript::make_shared>(f) + chaiscript::make_shared>>(f) ); } }; @@ -111,7 +111,7 @@ namespace chaiscript static Boxed_Value handle(const std::function &f) { return Boxed_Value( - chaiscript::make_shared>(f) + chaiscript::make_shared>>(f) ); } }; diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 2866d97..063c557 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -16,21 +16,14 @@ namespace chaiscript { namespace detail { - /** - * A constructor function, used for creating a new object - * of a given type with a given set of params - */ - template - std::shared_ptr constructor_(Params ... params) - { - return std::make_shared(params...); - } template Proxy_Function build_constructor_(Class (*)(Params...)) { - typedef std::shared_ptr (sig)(Params...); - return Proxy_Function(static_cast(new Proxy_Function_Impl(std::function(&(constructor_))))); + auto call = dispatch::detail::Constructor(); + + return Proxy_Function( + chaiscript::make_shared (Params...), decltype(call)>>(call)); } } } diff --git a/include/chaiscript/dispatchkit/proxy_functions.hpp b/include/chaiscript/dispatchkit/proxy_functions.hpp index 5856f45..35dc100 100644 --- a/include/chaiscript/dispatchkit/proxy_functions.hpp +++ b/include/chaiscript/dispatchkit/proxy_functions.hpp @@ -588,47 +588,6 @@ namespace chaiscript Func *m_dummy_func; }; - /// The standard typesafe function call implementation of Proxy_Function - /// It takes a std::function<> object and performs runtime - /// type checking of Boxed_Value parameters, in a type safe manner - template - class Proxy_Function_Impl : public Proxy_Function_Impl_Base - { - public: - Proxy_Function_Impl(std::function f) - : Proxy_Function_Impl_Base(detail::build_param_type_list(static_cast(nullptr))), - m_f(std::move(f)), m_dummy_func(nullptr) - { - } - - virtual ~Proxy_Function_Impl() {} - - virtual bool compare_types_with_cast(const std::vector &vals, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE - { - return detail::compare_types_cast(m_dummy_func, vals, t_conversions); - } - - virtual bool operator==(const Proxy_Function_Base &t_func) const CHAISCRIPT_OVERRIDE - { - return dynamic_cast *>(&t_func) != nullptr; - } - - std::function internal_function() const - { - return m_f; - } - - protected: - virtual Boxed_Value do_call(const std::vector ¶ms, const Type_Conversions &t_conversions) const CHAISCRIPT_OVERRIDE - { - return detail::Do_Call::result_type>::template go(m_f, params, t_conversions); - } - - - private: - std::function m_f; - Func *m_dummy_func; - }; class Assignable_Proxy_Function : public Proxy_Function_Impl_Base { diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 438c723..ecec5ea 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -15,76 +15,6 @@ namespace chaiscript { - namespace dispatch - { - namespace detail - { - - template - struct FunctionSignature - { - }; - - template - struct FunctionSignature > - { - typedef Sig Signature; - }; - - template - std::function to_function(Ret (*func)(Args...)) - { - return std::function(func); - } - - - template - std::function to_function(Ret (Class::*func)(Args...)) - { -#ifdef CHAISCRIPT_MSVC - /// \todo this std::mem_fn wrap shouldn't be necessary but type conversions for - /// std::function for member function pointers seems to be broken in MSVC - return std::function(std::mem_fn(func)); -#else - return std::function(func); -#endif - } - - template - std::function to_function(Ret (Class::*func)(Args...) const) - { -#if defined(CHAISCRIPT_MSVC) || defined(CHAISCRIPT_LIBCPP) - /// \todo this std::mem_fn wrap shouldn't be necessary but type conversions for - /// std::function for member function pointers seems to be broken in MSVC - return std::function([func](const Class &o, Args... args)->Ret { - return (o.*func)(std::forward(args)...); - }); -#else - return std::function(func); -#endif - } - - template - std::function to_function_callable(Ret (Class::*)(Args...), T t) - { - return std::function(t); - } - - template - std::function to_function_callable(Ret (Class::*)(Args...) const, T t) - { - return std::function(t); - } - - - template - auto to_function(T t) -> decltype(to_function_callable(&T::operator(), t)) - { - return to_function_callable(&T::operator(), t); - } - - } - } /// \brief Creates a new Proxy_Function object from a free function, member function or data member /// \param[in] t Function / member to expose @@ -142,10 +72,6 @@ namespace chaiscript return Proxy_Function( chaiscript::make_shared>(call)); -/* - return Proxy_Function( - chaiscript::make_shared::Signature>>(dispatch::detail::to_function(t_func))); -*/ }