Make for better error messages when a clone fails
This commit is contained in:
@@ -330,6 +330,13 @@ namespace chaiscript
|
|||||||
return std::vector<std::pair<std::string, std::multimap<std::string, Proxy_Function >::mapped_type> >(range.first, range.second);
|
return std::vector<std::pair<std::string, std::multimap<std::string, Proxy_Function >::mapped_type> >(range.first, range.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a function exists
|
||||||
|
*/
|
||||||
|
bool function_exists(const std::string &name) const
|
||||||
|
{
|
||||||
|
return m_functions.find(name) != m_functions.end();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a vector of all registered functions
|
* Get a vector of all registered functions
|
||||||
|
@@ -166,6 +166,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
engine.add(fun(boost::function<std::string (Boxed_Value)>(boost::bind(&chaiscript::type_name, boost::ref(engine), _1))),
|
engine.add(fun(boost::function<std::string (Boxed_Value)>(boost::bind(&chaiscript::type_name, boost::ref(engine), _1))),
|
||||||
"type_name");
|
"type_name");
|
||||||
|
engine.add(fun(boost::function<bool (const std::string &)>(boost::bind(&Eval_Engine::function_exists, boost::ref(engine), _1))),
|
||||||
|
"function_exists");
|
||||||
|
|
||||||
engine.add(vector_type<std::vector<Boxed_Value> >("Vector"));
|
engine.add(vector_type<std::vector<Boxed_Value> >("Vector"));
|
||||||
engine.add(string_type<std::string>("string"));
|
engine.add(string_type<std::string>("string"));
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
#define chaiscript_prelude CODE_STRING(\
|
#define chaiscript_prelude CODE_STRING(\
|
||||||
def new(x) { eval(type_name(x))(); } \
|
def new(x) { eval(type_name(x))(); } \
|
||||||
def clone(x) { eval(type_name(x))(x); } \
|
def clone(x) : function_exists(type_name(x)) { eval(type_name(x))(x); } \
|
||||||
# to_string for Pair()\n\
|
# to_string for Pair()\n\
|
||||||
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \
|
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \
|
||||||
"<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \
|
"<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \
|
||||||
|
Reference in New Issue
Block a user