Chai::add_global was added

Just a modification of the add_global_const. I don't see the point in
limiting the user to binding only constants to the global scope if the user
wishes to have a thread safe mutable object as a global. This was my case
anyway.
This commit is contained in:
Kim Simmons
2012-11-06 17:20:56 +01:00
parent 9832d1ce39
commit abcc6c9e3e
2 changed files with 22 additions and 0 deletions

View File

@@ -472,6 +472,22 @@ namespace chaiscript
}
}
void add_global(const Boxed_Value &obj, const std::string &name)
{
validate_object_name(name);
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_global_object_mutex);
if (m_state.m_global_objects.find(name) != m_state.m_global_objects.end())
{
throw exception::name_conflict_error(name);
} else {
m_state.m_global_objects.insert(std::make_pair(name, obj));
}
}
/**
* Adds a new scope to the stack
*/