Various cleanups prefering lambda to bind
This commit is contained in:
@@ -496,8 +496,7 @@ namespace chaiscript
|
|||||||
m->add(fun(&print), "print_string");
|
m->add(fun(&print), "print_string");
|
||||||
m->add(fun(&println), "println_string");
|
m->add(fun(&println), "println_string");
|
||||||
|
|
||||||
m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&bind_function, std::placeholders::_1))),
|
m->add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(&bind_function)), "bind");
|
||||||
"bind");
|
|
||||||
|
|
||||||
m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
|
m->add(fun(&shared_ptr_unconst_clone<dispatch::Proxy_Function_Base>), "clone");
|
||||||
m->add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "=");
|
m->add(fun(&ptr_assign<std::remove_const<dispatch::Proxy_Function_Base>::type>), "=");
|
||||||
|
@@ -53,29 +53,6 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<typename ... Rest>
|
|
||||||
struct Build_Param_Type_List;
|
|
||||||
|
|
||||||
template<typename Param, typename ... Rest>
|
|
||||||
struct Build_Param_Type_List<Param, Rest...>
|
|
||||||
{
|
|
||||||
static void build(std::vector<Type_Info> &t_params)
|
|
||||||
{
|
|
||||||
t_params.push_back(chaiscript::detail::Get_Type_Info<Param>::get());
|
|
||||||
Build_Param_Type_List<Rest...>::build(t_params);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 0th case
|
|
||||||
template<>
|
|
||||||
struct Build_Param_Type_List<>
|
|
||||||
{
|
|
||||||
static void build(std::vector<Type_Info> &)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by Proxy_Function_Impl to return a list of all param types
|
* Used by Proxy_Function_Impl to return a list of all param types
|
||||||
* it contains.
|
* it contains.
|
||||||
@@ -83,12 +60,8 @@ namespace chaiscript
|
|||||||
template<typename Ret, typename ... Params>
|
template<typename Ret, typename ... Params>
|
||||||
std::vector<Type_Info> build_param_type_list(Ret (*)(Params...))
|
std::vector<Type_Info> build_param_type_list(Ret (*)(Params...))
|
||||||
{
|
{
|
||||||
/// \todo this code was previously using { chaiscript::detail::Get_Type_Info<Ret>::get()... }
|
/// \note somehow this is responsible for a large part of the code generation
|
||||||
/// but this seems to indicate another bug with MSVC's uniform initializer lists
|
return { user_type<Ret>(), user_type<Params>()... };
|
||||||
std::vector<Type_Info> params;
|
|
||||||
params.push_back(chaiscript::detail::Get_Type_Info<Ret>::get());
|
|
||||||
Build_Param_Type_List<Params...>::build(params);
|
|
||||||
return params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -345,8 +345,10 @@ namespace chaiscript
|
|||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::function_exists, std::ref(m_engine)), "function_exists");
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_function_objects, std::ref(m_engine)), "get_functions");
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_scripting_objects, std::ref(m_engine)), "get_objects");
|
||||||
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(std::bind(&chaiscript::detail::Dispatch_Engine::call_exists, std::ref(m_engine), std::placeholders::_1))),
|
m_engine.add(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
|
||||||
"call_exists");
|
[this](const std::vector<Boxed_Value> &t_params) {
|
||||||
|
return m_engine.call_exists(t_params);
|
||||||
|
})), "call_exists");
|
||||||
m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
|
m_engine.add(fun<Boxed_Value (const dispatch::Proxy_Function_Base *, const std::vector<Boxed_Value> &)>(std::bind(&chaiscript::dispatch::Proxy_Function_Base::operator(), std::placeholders::_1, std::placeholders::_2, std::ref(m_engine.conversions()))), "call");
|
||||||
|
|
||||||
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name");
|
m_engine.add(fun(&chaiscript::detail::Dispatch_Engine::get_type_name, std::ref(m_engine)), "name");
|
||||||
|
@@ -732,9 +732,14 @@ namespace chaiscript
|
|||||||
numparams = 0;
|
numparams = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function
|
const auto &lambda_node = this->children.back();
|
||||||
(std::bind(chaiscript::eval::detail::eval_function, std::ref(t_ss), this->children.back(), t_param_names, std::placeholders::_1),
|
|
||||||
static_cast<int>(numparams), this->children.back())));
|
return Boxed_Value(Proxy_Function(new dispatch::Dynamic_Proxy_Function(
|
||||||
|
[&t_ss, lambda_node, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||||
|
{
|
||||||
|
return detail::eval_function(t_ss, lambda_node, t_param_names, t_params);
|
||||||
|
},
|
||||||
|
static_cast<int>(numparams), lambda_node)));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -800,19 +805,22 @@ namespace chaiscript
|
|||||||
std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
|
std::shared_ptr<dispatch::Dynamic_Proxy_Function> guard;
|
||||||
if (guardnode) {
|
if (guardnode) {
|
||||||
guard = std::shared_ptr<dispatch::Dynamic_Proxy_Function>
|
guard = std::shared_ptr<dispatch::Dynamic_Proxy_Function>
|
||||||
(new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function,
|
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||||
std::ref(t_ss), guardnode,
|
{
|
||||||
t_param_names, std::placeholders::_1), static_cast<int>(numparams), guardnode));
|
return detail::eval_function(t_ss, guardnode, t_param_names, t_params);
|
||||||
|
}, static_cast<int>(numparams), guardnode));
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const std::string & l_function_name = this->children[0]->text;
|
const std::string & l_function_name = this->children[0]->text;
|
||||||
const std::string & l_annotation = this->annotation?this->annotation->text:"";
|
const std::string & l_annotation = this->annotation?this->annotation->text:"";
|
||||||
|
const auto & func_node = this->children.back();
|
||||||
t_ss.add(Proxy_Function
|
t_ss.add(Proxy_Function
|
||||||
(new dispatch::Dynamic_Proxy_Function(std::bind(chaiscript::eval::detail::eval_function,
|
(new dispatch::Dynamic_Proxy_Function([&t_ss, guardnode, func_node, t_param_names](const std::vector<Boxed_Value> &t_params)
|
||||||
std::ref(t_ss), this->children.back(),
|
{
|
||||||
t_param_names, std::placeholders::_1), static_cast<int>(numparams), this->children.back(),
|
return detail::eval_function(t_ss, func_node, t_param_names, t_params);
|
||||||
l_annotation, guard)), l_function_name);
|
}, static_cast<int>(numparams), this->children.back(),
|
||||||
|
l_annotation, guard)), l_function_name);
|
||||||
}
|
}
|
||||||
catch (const exception::reserved_word_error &e) {
|
catch (const exception::reserved_word_error &e) {
|
||||||
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
|
throw exception::eval_error("Reserved word used as function name '" + e.word() + "'");
|
||||||
|
Reference in New Issue
Block a user