Handle user defined conversions of return types from functor

This commit is contained in:
Jason Turner
2015-07-04 08:43:52 -06:00
parent 484ff7a98b
commit 37120f486f
4 changed files with 12 additions and 23 deletions

View File

@@ -31,9 +31,9 @@ namespace chaiscript
struct Function_Caller_Ret
{
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions)
const std::vector<Boxed_Value> &params, const Type_Conversions *t_conversions)
{
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, t_conversions));
return boxed_cast<Ret>(dispatch::dispatch(t_funcs, params, t_conversions?*t_conversions:Type_Conversions()), t_conversions);
}
};
@@ -44,9 +44,9 @@ namespace chaiscript
struct Function_Caller_Ret<Ret, true>
{
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions)
const std::vector<Boxed_Value> &params, const Type_Conversions *t_conversions)
{
return Boxed_Number(dispatch::dispatch(t_funcs, params, t_conversions)).get_as<Ret>();
return Boxed_Number(dispatch::dispatch(t_funcs, params, t_conversions?*t_conversions:Type_Conversions())).get_as<Ret>();
}
};
@@ -58,9 +58,9 @@ namespace chaiscript
struct Function_Caller_Ret<void, false>
{
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions)
const std::vector<Boxed_Value> &params, const Type_Conversions *t_conversions)
{
dispatch::dispatch(t_funcs, params, t_conversions);
dispatch::dispatch(t_funcs, params, t_conversions?*t_conversions:Type_Conversions());
}
};
@@ -70,7 +70,7 @@ namespace chaiscript
template<typename Ret, typename ... Param>
struct Build_Function_Caller_Helper
{
Build_Function_Caller_Helper(std::vector<Const_Proxy_Function> t_funcs, const Type_Conversions &t_conversions)
Build_Function_Caller_Helper(std::vector<Const_Proxy_Function> t_funcs, const Type_Conversions *t_conversions)
: m_funcs(std::move(t_funcs)),
m_conversions(t_conversions)
{
@@ -107,11 +107,12 @@ namespace chaiscript
std::vector<Const_Proxy_Function> m_funcs;
Type_Conversions m_conversions;
const Type_Conversions *m_conversions;
};
/// \todo what happens if t_conversions is deleted out from under us?!
template<typename Ret, typename ... Params>
std::function<Ret (Params...)> build_function_caller_helper(Ret (Params...), const std::vector<Const_Proxy_Function> &funcs, const Type_Conversions *t_conversions)
{
@@ -131,7 +132,7 @@ namespace chaiscript
}
*/
return std::function<Ret (Params...)>(Build_Function_Caller_Helper<Ret, Params...>(funcs, t_conversions?*t_conversions:Type_Conversions()));
return std::function<Ret (Params...)>(Build_Function_Caller_Helper<Ret, Params...>(funcs, t_conversions));
}
}
}