Enhance "is_type" to be more accurate and to work with Dynamic_Object types

This commit is contained in:
Jason Turner
2009-10-13 03:31:56 +00:00
parent 720eabcb16
commit b1e892487f
2 changed files with 20 additions and 9 deletions

View File

@@ -23,6 +23,7 @@
#include "type_info.hpp"
#include "proxy_functions.hpp"
#include "proxy_constructors.hpp"
#include "dynamic_object.hpp"
#include "../chaiscript_threading.hpp"
namespace chaiscript
@@ -577,10 +578,20 @@ namespace chaiscript
bool is_type(const std::string &user_typename, Boxed_Value r) const
{
try {
return get_type(user_typename) == r.get_type_info();
if (get_type(user_typename).bare_equal(r.get_type_info()))
{
return true;
}
} catch (const std::range_error &) {
return false;
}
try {
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(r);
return d.get_type_name() == user_typename;
} catch (const std::bad_cast &) {
}
return false;
}
std::string type_name(Boxed_Value obj) const