diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index 1f0e175..36edadb 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -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(r); + return d.get_type_name() == user_typename; + } catch (const std::bad_cast &) { + } + + return false; } std::string type_name(Boxed_Value obj) const diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index a5b334b..3476d6e 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -281,27 +281,27 @@ def zip(x, y) { \n\ zip_with(collate, x, y); \n\ }\n\ # Returns the position of the second value string in the first value string\n\ -def string::find(substr) : type_name(substr) == "string" { \n\ +def string::find(substr) : is_type(substr, "string") { \n\ int(find(this, substr, size_t(0))); \n\ } \n\ # Returns the position of last match of the second value string in the first value string\n\ -def string::rfind(substr) : type_name(substr) == "string" { \n\ +def string::rfind(substr) : is_type(substr, "string") { \n\ int(rfind(this, substr, size_t(-1))); \n\ } \n\ # Returns the position of the first match of elements in the second value string in the first value string\n\ -def string::find_first_of(list) : type_name(list) == "string" { \n\ +def string::find_first_of(list) : is_type(list, "string") { \n\ int(find_first_of(this, list, size_t(0))); \n\ } \n\ # Returns the position of the last match of elements in the second value string in the first value string\n\ -def string::find_last_of(list) : type_name(list) == "string" { \n\ +def string::find_last_of(list) : is_type(list, "string") { \n\ int(find_last_of(this, list, size_t(-1))); \n\ } \n\ # Returns the position of the first non-matching element in the second value string in the first value string\n\ -def string::find_first_not_of(list) : type_name(list) == "string" { \n\ +def string::find_first_not_of(list) : is_type(list, "string") { \n\ int(find_first_not_of(this, list, size_t(0))); \n\ } \n\ # Returns the position of the last non-matching element in the second value string in the first value string\n\ -def string::find_last_not_of(list) : type_name(list) == "string" { \n\ +def string::find_last_not_of(list) : is_type(list, "string") { \n\ int(find_last_not_of(this, list, size_t(-1))); \n\ } \n\ def string::ltrim() { \n\ @@ -313,7 +313,7 @@ def string::rtrim() { \n\ def string::trim() { \n\ ltrim(rtrim(this)); \n\ } \n\ -def find(container, value, compare_func) : call_exists(range, container) && type_name(compare_func) == "function" { \n\ +def find(container, value, compare_func) : call_exists(range, container) && is_type(compare_func, "function") { \n\ var range = range(container); \n\ while (!range.empty()) { \n\ if (compare_func(range.front(), value)) { \n\