Add Type_Info type and add *_type objects at time of type registration.
This commit is contained in:
@@ -528,11 +528,28 @@ namespace chaiscript
|
||||
m->add(fun(&Dynamic_Object::get_attr), "get_attr");
|
||||
m->eval("def Dynamic_Object::clone() { var new_o := Dynamic_Object(this.get_type_name()); for_each(this.get_attrs(), bind(fun(new_o, x) { new_o.get_attr(x.first) = x.second; }, new_o, _) ); return new_o; }");
|
||||
|
||||
m->add(fun(&Boxed_Value::is_undef), "is_undef");
|
||||
m->add(fun(&Boxed_Value::is_null), "is_null");
|
||||
m->add(fun(&Boxed_Value::is_const), "is_const");
|
||||
m->add(fun(&Boxed_Value::is_ref), "is_reference");
|
||||
m->add(fun(&Boxed_Value::is_pointer), "is_pointer");
|
||||
m->add(fun(&Boxed_Value::is_undef), "is_var_undef");
|
||||
m->add(fun(&Boxed_Value::is_null), "is_var_null");
|
||||
m->add(fun(&Boxed_Value::is_const), "is_var_const");
|
||||
m->add(fun(&Boxed_Value::is_ref), "is_var_reference");
|
||||
m->add(fun(&Boxed_Value::is_pointer), "is_var_pointer");
|
||||
m->add(fun(&Boxed_Value::is_type), "is_type");
|
||||
|
||||
m->add(fun(&Boxed_Value::get_type_info), "get_type_info");
|
||||
m->add(user_type<Type_Info>(), "Type_Info");
|
||||
|
||||
|
||||
operators::equal<Type_Info>(m);
|
||||
|
||||
m->add(fun(&Type_Info::is_const), "is_type_const");
|
||||
m->add(fun(&Type_Info::is_reference), "is_type_reference");
|
||||
m->add(fun(&Type_Info::is_void), "is_type_void");
|
||||
m->add(fun(&Type_Info::is_undef), "is_type_undef");
|
||||
m->add(fun(&Type_Info::is_pointer), "is_type_pointer");
|
||||
m->add(fun(&Type_Info::name), "cpp_name");
|
||||
m->add(fun(&Type_Info::bare_name), "cpp_bare_name");
|
||||
m->add(fun(&Type_Info::bare_equal), "bare_equal");
|
||||
|
||||
|
||||
basic_constructors<bool>("bool", m);
|
||||
operators::assign<bool>(m);
|
||||
|
@@ -315,6 +315,11 @@ namespace chaiscript
|
||||
return m_data->m_type_info.is_const();
|
||||
}
|
||||
|
||||
bool is_type(const Type_Info &ti) const
|
||||
{
|
||||
return m_data->m_type_info.bare_equal(ti);
|
||||
}
|
||||
|
||||
bool is_null() const
|
||||
{
|
||||
if (m_data->m_is_null)
|
||||
|
@@ -43,6 +43,7 @@ namespace chaiscript
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
//Add a bit of chaiscript to eval during module implementation
|
||||
Module &eval(const std::string &str)
|
||||
{
|
||||
@@ -50,6 +51,11 @@ namespace chaiscript
|
||||
return *this;
|
||||
}
|
||||
|
||||
Module &add(const boost::shared_ptr<Module> &m)
|
||||
{
|
||||
m->apply(*this, *this);
|
||||
return *m;
|
||||
}
|
||||
|
||||
template<typename Eval, typename Engine>
|
||||
void apply(Eval &t_eval, Engine &t_engine) const
|
||||
@@ -411,6 +417,8 @@ namespace chaiscript
|
||||
*/
|
||||
void add(const Type_Info &ti, const std::string &name)
|
||||
{
|
||||
add_global_const(const_var(ti), name + "_type");
|
||||
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
boost::unique_lock<boost::shared_mutex> l(m_mutex);
|
||||
#endif
|
||||
|
@@ -87,6 +87,17 @@ namespace chaiscript
|
||||
bool is_reference() const { return m_is_reference; }
|
||||
bool is_void() const { return m_is_void; }
|
||||
bool is_undef() const { return m_is_undef || m_bare_type_info == 0; }
|
||||
bool is_pointer() const { return m_is_pointer; }
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
if (m_type_info)
|
||||
{
|
||||
return m_type_info->name();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
std::string bare_name() const
|
||||
{
|
||||
|
@@ -535,6 +535,8 @@ namespace chaiscript
|
||||
engine.add(fun(&Eval_Engine::type_name, boost::ref(engine)), "type_name");
|
||||
engine.add(fun(&Eval_Engine::function_exists, boost::ref(engine)), "function_exists");
|
||||
|
||||
engine.add(fun(&Eval_Engine::get_type_name, boost::ref(engine)), "name");
|
||||
|
||||
|
||||
typedef void (ChaiScript_System<Eval_Engine>::*load_mod_1)(const std::string&);
|
||||
typedef void (ChaiScript_System<Eval_Engine>::*load_mod_2)(const std::string&, const std::string&);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
print(1.is_const());
|
||||
print(1.is_reference());
|
||||
print(1.is_pointer());
|
||||
print(1.is_null());
|
||||
print(1.is_undef());
|
||||
print(1.is_var_const());
|
||||
print(1.is_var_reference());
|
||||
print(1.is_var_pointer());
|
||||
print(1.is_var_null());
|
||||
print(1.is_var_undef());
|
||||
var i;
|
||||
print(i.is_undef());
|
||||
print(i.is_var_undef());
|
||||
|
@@ -1,4 +1,4 @@
|
||||
var i;
|
||||
print(i.is_undef());
|
||||
print(i.is_var_undef());
|
||||
i = 5;
|
||||
print(i.is_undef());
|
||||
print(i.is_var_undef());
|
||||
|
10
unittests/type_info.chai
Normal file
10
unittests/type_info.chai
Normal file
@@ -0,0 +1,10 @@
|
||||
print(string_type.name());
|
||||
print(string_type.is_type_const());
|
||||
print(string_type.is_type_reference());
|
||||
print(string_type.is_type_void());
|
||||
print(string_type.is_type_undef());
|
||||
print(string_type.is_type_pointer());
|
||||
print("string".get_type_info().name());
|
||||
print(string_type.bare_equal("string".get_type_info()));
|
||||
|
||||
print("bob".is_type(string_type));
|
9
unittests/type_info.txt
Normal file
9
unittests/type_info.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
string
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
false
|
||||
string
|
||||
true
|
||||
true
|
Reference in New Issue
Block a user