mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-02-07 02:09:57 +08:00
Add "is_type" utility function and register "function" as a registered typename
This commit is contained in:
parent
b191d5a2ee
commit
27e72d117f
@ -457,6 +457,15 @@ namespace dispatchkit
|
|||||||
return l.get_type_info() == r.get_type_info();
|
return l.get_type_info() == r.get_type_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool is_type(const Dispatch_Engine &e, const std::string &type_name, Boxed_Value r)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return e.get_type(type_name) == r.get_type_info();
|
||||||
|
} catch (const std::range_error &) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Boxed_Value bind_function(const std::vector<Boxed_Value> ¶ms)
|
static Boxed_Value bind_function(const std::vector<Boxed_Value> ¶ms)
|
||||||
{
|
{
|
||||||
if (params.size() < 2)
|
if (params.size() < 2)
|
||||||
@ -488,6 +497,8 @@ namespace dispatchkit
|
|||||||
|
|
||||||
s.register_type<std::string>("string");
|
s.register_type<std::string>("string");
|
||||||
|
|
||||||
|
s.register_type<Proxy_Function>("function");
|
||||||
|
|
||||||
add_basic_constructors<bool>(s, "bool");
|
add_basic_constructors<bool>(s, "bool");
|
||||||
add_basic_constructors<std::string>(s, "string");
|
add_basic_constructors<std::string>(s, "string");
|
||||||
add_oper_assign<std::string>(s);
|
add_oper_assign<std::string>(s);
|
||||||
@ -516,6 +527,8 @@ namespace dispatchkit
|
|||||||
|
|
||||||
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
|
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
|
||||||
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
||||||
|
s.register_function(boost::function<bool (const std::string &, Boxed_Value)>(boost::bind(&is_type, s, _1, _2)),
|
||||||
|
"is_type");
|
||||||
|
|
||||||
s.add_object("_", Placeholder_Object());
|
s.add_object("_", Placeholder_Object());
|
||||||
|
|
||||||
|
|||||||
@ -169,6 +169,17 @@ namespace dispatchkit
|
|||||||
m_types.insert(std::make_pair(name, Get_Type_Info<Type>::get()));
|
m_types.insert(std::make_pair(name, Get_Type_Info<Type>::get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Type_Info get_type(const std::string &name) const
|
||||||
|
{
|
||||||
|
Type_Name_Map::const_iterator itr = m_types.find(name);
|
||||||
|
if (itr != m_types.end())
|
||||||
|
{
|
||||||
|
return itr->second;
|
||||||
|
} else {
|
||||||
|
throw std::range_error("Type Not Known");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Type_Name_Map::value_type> get_types() const
|
std::vector<Type_Name_Map::value_type> get_types() const
|
||||||
{
|
{
|
||||||
return std::vector<Type_Name_Map::value_type>(m_types.begin(), m_types.end());
|
return std::vector<Type_Name_Map::value_type>(m_types.begin(), m_types.end());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user