From 8d96abe73091c2eb6d5c53a2d94fb5884bbcb5fa Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 24 Mar 2014 14:09:20 -0600 Subject: [PATCH] Fix test for overload registration with add_class utility --- .../dispatchkit/register_function.hpp | 36 ++++++++++--------- unittests/utility_test.cpp | 9 +++-- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/include/chaiscript/dispatchkit/register_function.hpp b/include/chaiscript/dispatchkit/register_function.hpp index 5dfdeed2..c1993b39 100644 --- a/include/chaiscript/dispatchkit/register_function.hpp +++ b/include/chaiscript/dispatchkit/register_function.hpp @@ -73,23 +73,6 @@ namespace chaiscript } } - /// \brief Creates a new Proxy_Function object from a std::function object - /// \param[in] f std::function to expose to ChaiScript - /// - /// \b Example: - /// \code - /// std::function f = get_some_function(); - /// chaiscript::ChaiScript chai; - /// chai.add(fun(f), "some_function"); - /// \endcode - /// - /// \sa \ref addingfunctions - template - Proxy_Function fun(const std::function &f) - { - return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); - } - /// \brief Creates a new Proxy_Function object from a free function, member function or data member /// \param[in] t Function / member to expose /// @@ -116,6 +99,25 @@ namespace chaiscript return dispatch::detail::Fun_Helper::value>::go(t); } + + /// \brief Creates a new Proxy_Function object from a std::function object + /// \param[in] f std::function to expose to ChaiScript + /// + /// \b Example: + /// \code + /// std::function f = get_some_function(); + /// chaiscript::ChaiScript chai; + /// chai.add(fun(f), "some_function"); + /// \endcode + /// + /// \sa \ref addingfunctions + template + Proxy_Function fun(const std::function &f) + { + return Proxy_Function(new dispatch::Proxy_Function_Impl(f)); + } + + /// \brief Creates a new Proxy_Function object from a free function, member function or data member and binds the first parameter of it /// \param[in] t Function / member to expose /// \param[in] q Value to bind to first parameter diff --git a/unittests/utility_test.cpp b/unittests/utility_test.cpp index b611fd63..12796588 100644 --- a/unittests/utility_test.cpp +++ b/unittests/utility_test.cpp @@ -1,5 +1,7 @@ +#include #include #include +#include class Test { @@ -18,6 +20,7 @@ int main() using namespace chaiscript; + /// \todo fix overload resolution for fun<> chaiscript::utility::add_class(*m, "Test", { constructor(), @@ -25,9 +28,9 @@ int main() { {fun(&Test::function), "function"}, {fun(&Test::function2), "function2"}, {fun(&Test::function3), "function3"}, - {fun(&Test::functionOverload), "functionOverload"}, - {fun(&Test::functionOverload), "functionOverload"}, - {fun(&Test::operator=), "="} + {fun(static_cast(&Test::functionOverload)), "functionOverload" }, + {fun(static_cast(&Test::functionOverload)), "functionOverload" }, + {fun(static_cast(&Test::operator=)), "=" } } );