diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index d825a9a..edbd7ac 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -463,7 +463,7 @@ namespace chaiscript /** * return true if the Boxed_Value matches the registered type by name */ - static bool is_type(const Dispatch_Engine &e, const std::string &user_typename, Boxed_Value r) + bool is_type(const Dispatch_Engine &e, const std::string &user_typename, Boxed_Value r) { try { return e.get_type(user_typename) == r.get_type_info(); @@ -472,6 +472,11 @@ namespace chaiscript } } + std::string type_name(const Dispatch_Engine &e, Boxed_Value obj) + { + return e.get_type_name(obj.get_type_info()); + } + } #endif diff --git a/include/chaiscript/language/chaiscript_engine.hpp b/include/chaiscript/language/chaiscript_engine.hpp index 0ffb0d0..8460008 100644 --- a/include/chaiscript/language/chaiscript_engine.hpp +++ b/include/chaiscript/language/chaiscript_engine.hpp @@ -148,6 +148,8 @@ namespace chaiscript engine.add(fun(boost::function(boost::bind(&is_type, boost::ref(engine), _2, _1))), "is_type"); + engine.add(fun(boost::function(boost::bind(&chaiscript::type_name, boost::ref(engine), _1))), + "type_name"); engine.add(vector_type >("Vector")); engine.add(string_type("string")); diff --git a/include/chaiscript/language/chaiscript_prelude.hpp b/include/chaiscript/language/chaiscript_prelude.hpp index 28b83a4..e7b23e1 100644 --- a/include/chaiscript/language/chaiscript_prelude.hpp +++ b/include/chaiscript/language/chaiscript_prelude.hpp @@ -12,7 +12,7 @@ #define CODE_STRING(x, y) #x ", " #y #define chaiscript_prelude CODE_STRING(\ -def new(x) { var retval = clone(x); clear(retval); retval; } \ +def new(x) { eval(type_name(x))(); } \ # to_string for Pair()\n\ def to_string(x) : call_exists(first, x) && call_exists(second, x) { \ "<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \