diff --git a/include/chaiscript/dispatchkit/dynamic_object.hpp b/include/chaiscript/dispatchkit/dynamic_object.hpp index 3a4eaa8..112e836 100644 --- a/include/chaiscript/dispatchkit/dynamic_object.hpp +++ b/include/chaiscript/dispatchkit/dynamic_object.hpp @@ -60,7 +60,7 @@ namespace chaiscript const std::string &t_type_name, const Proxy_Function &t_func, const boost::optional &t_ti = boost::optional()) - : Proxy_Function_Base(t_func->get_param_types()), + : Proxy_Function_Base(build_param_types(t_func->get_param_types(), t_ti)), m_type_name(t_type_name), m_func(t_func), m_ti(t_ti) { assert( (t_func->get_arity() > 0 || t_func->get_arity() < 0) @@ -125,6 +125,22 @@ namespace chaiscript } private: + static std::vector build_param_types( + const std::vector &t_inner_types, boost::optional t_objectti) + { + if (t_objectti) + { + std::vector types(t_inner_types); + + assert(types.size() > 1); + assert(types[1].bare_equal(user_type())); + types[1] = *t_objectti; + return types; + } else { + return t_inner_types; + } + } + static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name, const boost::optional &ti) { diff --git a/unittests/function_introspection.chai b/unittests/function_introspection.chai index fa83955..7f8e730 100644 --- a/unittests/function_introspection.chai +++ b/unittests/function_introspection.chai @@ -5,6 +5,10 @@ def test_function(a) return a; } + + + +// test_function tests assert_equal(test_function.get_arity(), 1); assert_equal(test_function.get_annotation(), "#Test Function Description\n"); assert_equal(test_function.get_contained_functions().size(), 0); @@ -16,6 +20,24 @@ assert_not_equal(test_function, `+`); assert_equal(test_function.call([1]), 1); +// dynamic object function tests + +def int::test_fun() +{ + return this; +} + +assert_equal(test_fun.get_arity(), 1); +assert_equal(test_fun.get_contained_functions.size(), 1); +assert_equal(test_fun.get_param_types().size(), 2); +assert_equal(test_fun, test_fun); +var test_fun_types = test_fun.get_param_types(); +assert_equal(true, test_fun_types[0].bare_equal(Object_type)); +assert_equal(true, test_fun_types[1].bare_equal(int_type)); + + +// built-ins tests + assert_equal(2, `==`.get_arity()); // < should be the merging of two functions bool <(PODObject, PODObject) and bool <(string, string)