Allow for automatic conversion of arithmetic types
for returns from chaiscript function wrappers
This commit is contained in:
parent
db8be03cee
commit
7fade8e841
@ -27,12 +27,11 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal helper class for handling the return
|
* Internal helper class for handling the return
|
||||||
* value of a build_function_caller
|
* value of a build_function_caller
|
||||||
*/
|
*/
|
||||||
template<typename Ret>
|
template<typename Ret, bool is_arithmetic>
|
||||||
struct Function_Caller_Ret
|
struct Function_Caller_Ret
|
||||||
{
|
{
|
||||||
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
@ -42,11 +41,25 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specialization for arithmetic return types
|
||||||
|
*/
|
||||||
|
template<typename Ret>
|
||||||
|
struct Function_Caller_Ret<Ret, true>
|
||||||
|
{
|
||||||
|
static Ret call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
|
const std::vector<Boxed_Value> ¶ms, const Dynamic_Cast_Conversions &t_conversions)
|
||||||
|
{
|
||||||
|
return Boxed_Number(dispatch::dispatch(t_funcs, params, t_conversions)).get_as<Ret>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specialization for void return types
|
* Specialization for void return types
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
struct Function_Caller_Ret<void>
|
struct Function_Caller_Ret<void, false>
|
||||||
{
|
{
|
||||||
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
static void call(const std::vector<Const_Proxy_Function> &t_funcs,
|
||||||
const std::vector<Boxed_Value> ¶ms, const Dynamic_Cast_Conversions &t_conversions)
|
const std::vector<Boxed_Value> ¶ms, const Dynamic_Cast_Conversions &t_conversions)
|
||||||
@ -83,7 +96,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
BOOST_PP_REPEAT(n, addparam, ~);
|
BOOST_PP_REPEAT(n, addparam, ~);
|
||||||
|
|
||||||
return Function_Caller_Ret<Ret>::call(funcs, params, t_conversions);
|
return Function_Caller_Ret<Ret, boost::is_arithmetic<Ret>::value>::call(funcs, params, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user