mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-06 16:57:04 +08:00
Add support for getting command argument types as a vector
This commit is contained in:
parent
5424b6be41
commit
1980ba840c
@ -3,13 +3,35 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "scripting_object.hpp"
|
#include "scripting_object.hpp"
|
||||||
|
#include "scripting_type_info.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
template<typename Ret>
|
||||||
|
std::vector<Type_Info> build_param_type_list(const boost::function<Ret ()> &f)
|
||||||
|
{
|
||||||
|
return std::vector<Type_Info>();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename Param1>
|
||||||
|
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (Param1)> &f)
|
||||||
|
{
|
||||||
|
std::vector<Type_Info> ti;
|
||||||
|
ti.push_back(Get_Type_Info<Param1>()());
|
||||||
|
return ti;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Ret, typename Param1, typename Param2>
|
||||||
|
std::vector<Type_Info> build_param_type_list(const boost::function<Ret (Param1, Param2)> &f)
|
||||||
|
{
|
||||||
|
std::vector<Type_Info> ti;
|
||||||
|
ti.push_back(Get_Type_Info<Param1>()());
|
||||||
|
ti.push_back(Get_Type_Info<Param2>()());
|
||||||
|
return ti;
|
||||||
|
}
|
||||||
|
|
||||||
// handle_return implementations
|
// handle_return implementations
|
||||||
template<typename Ret>
|
template<typename Ret>
|
||||||
@ -83,6 +105,8 @@ class Function_Handler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual Scripting_Object operator()(const std::vector<Scripting_Object> ¶ms) = 0;
|
virtual Scripting_Object operator()(const std::vector<Scripting_Object> ¶ms) = 0;
|
||||||
|
virtual std::vector<Type_Info> get_param_types() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Func>
|
template<typename Func>
|
||||||
@ -99,6 +123,11 @@ class Function_Handler_Impl : public Function_Handler
|
|||||||
return call_func(m_f, params);
|
return call_func(m_f, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::vector<Type_Info> get_param_types()
|
||||||
|
{
|
||||||
|
return build_param_type_list(m_f);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Func m_f;
|
Func m_f;
|
||||||
};
|
};
|
||||||
@ -125,7 +154,5 @@ std::vector<Scripting_Object> build_param_list(const Scripting_Object &so1, con
|
|||||||
return sos;
|
return sos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user