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:
parent
9832d1ce39
commit
abcc6c9e3e
@ -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
|
||||
*/
|
||||
|
@ -446,6 +446,12 @@ namespace chaiscript
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChaiScript &add_global(const Boxed_Value &t_bv, const std::string &t_name)
|
||||
{
|
||||
m_engine.add_global(t_bv, t_name);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/// \brief Represents the current state of the ChaiScript system. State and be saved and restored
|
||||
/// \sa ChaiScript::get_state
|
||||
/// \sa ChaiScript::set_state
|
||||
|
Loading…
x
Reference in New Issue
Block a user