Skip to content

Commit

Permalink
Fix test for overload registration with add_class utility
Browse files Browse the repository at this point in the history
  • Loading branch information
lefticus committed Mar 24, 2014
1 parent c021cc9 commit 8d96abe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
36 changes: 19 additions & 17 deletions include/chaiscript/dispatchkit/register_function.hpp
Expand Up @@ -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<int (char, float, std::string)> f = get_some_function();
/// chaiscript::ChaiScript chai;
/// chai.add(fun(f), "some_function");
/// \endcode
///
/// \sa \ref addingfunctions
template<typename T>
Proxy_Function fun(const std::function<T> &f)
{
return Proxy_Function(new dispatch::Proxy_Function_Impl<T>(f));
}

/// \brief Creates a new Proxy_Function object from a free function, member function or data member
/// \param[in] t Function / member to expose
///
Expand All @@ -116,6 +99,25 @@ namespace chaiscript
return dispatch::detail::Fun_Helper<std::is_member_object_pointer<T>::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<int (char, float, std::string)> f = get_some_function();
/// chaiscript::ChaiScript chai;
/// chai.add(fun(f), "some_function");
/// \endcode
///
/// \sa \ref addingfunctions
template<typename T>
Proxy_Function fun(const std::function<T> &f)
{
return Proxy_Function(new dispatch::Proxy_Function_Impl<T>(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
Expand Down
9 changes: 6 additions & 3 deletions unittests/utility_test.cpp
@@ -1,5 +1,7 @@
#include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp>
#include <chaiscript/utility/utility.hpp>
#include <functional>

class Test
{
Expand All @@ -18,16 +20,17 @@ int main()

using namespace chaiscript;

/// \todo fix overload resolution for fun<>
chaiscript::utility::add_class<Test>(*m,
"Test",
{ constructor<Test ()>(),
constructor<Test (const Test &)>() },
{ {fun(&Test::function), "function"},
{fun(&Test::function2), "function2"},
{fun(&Test::function3), "function3"},
{fun<std::string (Test::*)(double)>(&Test::functionOverload), "functionOverload"},
{fun<std::string (Test::*)(int)>(&Test::functionOverload), "functionOverload"},
{fun<Test & (Test::*)(const Test &)>(&Test::operator=), "="}
{fun(static_cast<std::string(Test::*)(double)>(&Test::functionOverload)), "functionOverload" },
{fun(static_cast<std::string(Test::*)(int)>(&Test::functionOverload)), "functionOverload" },
{fun(static_cast<Test & (Test::*)(const Test &)>(&Test::operator=)), "=" }

}
);
Expand Down

0 comments on commit 8d96abe

Please sign in to comment.