Register string as a container type and update the prelue to guard to_string for ranges against strings.

This commit is contained in:
Jason Turner 2009-07-03 16:37:18 +00:00
parent 27e72d117f
commit 310dd030ac
4 changed files with 18 additions and 15 deletions

View File

@ -70,6 +70,7 @@ namespace chaiscript
void build_eval_system() {
dispatchkit::Bootstrap::bootstrap(engine);
dispatchkit::bootstrap_vector<std::vector<dispatchkit::Boxed_Value> >(engine, "Vector");
dispatchkit::bootstrap_string<std::string>(engine, "string");
dispatchkit::bootstrap_map<std::map<std::string, dispatchkit::Boxed_Value> >(engine, "Map");
dispatchkit::bootstrap_pair<std::pair<dispatchkit::Boxed_Value, dispatchkit::Boxed_Value > >(engine, "Pair");

View File

@ -8,7 +8,7 @@ const char *chaiscript_prelude = " \
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \n\
\"<\" + x.first.to_string() + \", \" + x.second.to_string() + \">\"\n\
}\n\
def to_string(x) : call_exists(range, x) { \n\
def to_string(x) : !is_type(\"string\", x) && call_exists(range, x) { \n\
\"[\" + x.join(\", \") + \"]\"\n\
}\n\
def to_string(x) { \n\

View File

@ -494,16 +494,12 @@ namespace dispatchkit
static void bootstrap(Dispatch_Engine &s)
{
s.register_type<void>("void");
s.register_type<std::string>("string");
s.register_type<bool>("bool");
s.register_type<Proxy_Function>("function");
add_basic_constructors<bool>(s, "bool");
add_basic_constructors<std::string>(s, "string");
add_oper_assign<std::string>(s);
register_function(s, &to_string<const std::string &>, "internal_to_string");
register_function(s, &to_string<bool>, "internal_to_string");
register_function(s, &unknown_assign, "=");
@ -518,16 +514,12 @@ namespace dispatchkit
add_opers_comparison_pod(s);
add_opers_arithmetic_pod(s);
add_oper_add<std::string>(s);
add_oper_add_equals <std::string>(s);
add_opers_comparison<std::string>(s);
register_function(s, &print, "print_string");
register_function(s, &println, "println_string");
s.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(s))), "dump_system");
s.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
s.register_function(boost::function<bool (const std::string &, Boxed_Value)>(boost::bind(&is_type, s, _1, _2)),
s.register_function(boost::function<bool (const std::string &, Boxed_Value)>(boost::bind(&is_type, boost::ref(s), _1, _2)),
"is_type");
s.add_object("_", Placeholder_Object());

View File

@ -91,10 +91,8 @@ namespace dispatchkit
template<typename Assignable>
void bootstrap_assignable(Dispatch_Engine &system, const std::string &type)
{
system.register_function(
boost::function<Assignable &(Assignable*, const Assignable&)>(&Assignable::operator=), "=");
system.register_function(build_constructor<Assignable, const Assignable &>(), type);
system.register_function(build_constructor<Assignable, const Assignable &>(), "clone");
add_basic_constructors<Assignable>(system, type);
add_oper_assign<Assignable>(system);
}
template<typename ContainerType>
@ -209,6 +207,18 @@ namespace dispatchkit
bootstrap_unique_sorted_associative_container<MapType>(system, type);
bootstrap_pair_associative_container<MapType>(system, type);
}
template<typename String>
void bootstrap_string(Dispatch_Engine &system, const std::string &type)
{
system.register_type<String>(type);
add_oper_add<String>(system);
add_oper_add_equals<String>(system);
add_opers_comparison<String>(system);
bootstrap_random_access_container<String>(system, type);
bootstrap_sequence<String>(system, type);
}
}
#endif