Make def more efficient, fix to_string(string)

This commit is contained in:
Jason Turner
2014-11-13 12:28:52 -07:00
parent 63a083b47b
commit cf49b1b30c
2 changed files with 4 additions and 8 deletions

View File

@@ -443,7 +443,7 @@ namespace chaiscript
operators::assign<bool>(m);
operators::equal<bool>(m);
m->add(fun(&to_string<const std::string &>), "to_string");
m->add(fun<std::string (const std::string &t_ss)>([](const std::string &s) -> std::string { return s; }), "to_string");
m->add(fun(&Bootstrap::bool_to_string), "to_string");
m->add(fun(&unknown_assign), "=");
m->add(fun(&throw_exception), "throw");

View File

@@ -443,17 +443,13 @@ namespace chaiscript
/// Adds a named object to the current scope
/// \warning This version does not check the validity of the name
/// it is meant for internal use only
void add_object(const std::string &name, const Boxed_Value &obj) const
{
auto &stack = get_stack_data();
validate_object_name(name);
auto &scope = stack.back();
if (scope.find(name) != scope.end())
if (!get_stack_data().back().insert(std::make_pair(name, obj)).second)
{
throw chaiscript::exception::name_conflict_error(name);
} else {
scope.insert(std::make_pair(name, obj));
}
}