Merge remote-tracking branch 'zoomulator/master'

Adding zoomulator's patches for allowing of non-const globals if the user
wants to.
This commit is contained in:
Jason Turner
2013-11-27 08:06:39 -07:00
2 changed files with 22 additions and 0 deletions

View File

@@ -477,6 +477,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 * Adds a new scope to the stack
*/ */

View File

@@ -454,6 +454,12 @@ namespace chaiscript
return *this; 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 /// \brief Represents the current state of the ChaiScript system. State and be saved and restored
/// \sa ChaiScript::get_state /// \sa ChaiScript::get_state
/// \sa ChaiScript::set_state /// \sa ChaiScript::set_state