parent
209d6ed2e4
commit
dfd04c8291
@ -535,9 +535,9 @@ namespace chaiscript
|
|||||||
|
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
const auto itr = m_state.m_global_objects.find(name);
|
const auto itr = m_state.m_global_objects.find(name);
|
||||||
if (itr == m_state.m_global_objects.end())
|
if (itr == m_state.m_global_objects.end())
|
||||||
{
|
{
|
||||||
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
||||||
return obj;
|
return obj;
|
||||||
} else {
|
} else {
|
||||||
@ -549,32 +549,32 @@ namespace chaiscript
|
|||||||
/// Adds a new global (non-const) shared object, between all the threads
|
/// Adds a new global (non-const) shared object, between all the threads
|
||||||
void add_global(const Boxed_Value &obj, const std::string &name)
|
void add_global(const Boxed_Value &obj, const std::string &name)
|
||||||
{
|
{
|
||||||
validate_object_name(name);
|
validate_object_name(name);
|
||||||
|
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
if (m_state.m_global_objects.find(name) != m_state.m_global_objects.end())
|
if (m_state.m_global_objects.find(name) != m_state.m_global_objects.end())
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::name_conflict_error(name);
|
throw chaiscript::exception::name_conflict_error(name);
|
||||||
} else {
|
} else {
|
||||||
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates an existing global shared object or adds a new global shared object if not found
|
/// Updates an existing global shared object or adds a new global shared object if not found
|
||||||
void set_global(const Boxed_Value &obj, const std::string &name)
|
void set_global(const Boxed_Value &obj, const std::string &name)
|
||||||
{
|
{
|
||||||
validate_object_name(name);
|
validate_object_name(name);
|
||||||
|
|
||||||
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::unique_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
const auto itr = m_state.m_global_objects.find(name);
|
const auto itr = m_state.m_global_objects.find(name);
|
||||||
if (itr != m_state.m_global_objects.end())
|
if (itr != m_state.m_global_objects.end())
|
||||||
{
|
{
|
||||||
itr->second.assign(obj);
|
itr->second.assign(obj);
|
||||||
} else {
|
} else {
|
||||||
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
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
|
||||||
|
@ -622,17 +622,17 @@ namespace chaiscript
|
|||||||
/// ChaiScript is thread-safe but provides no threading locking mechanism to the script
|
/// ChaiScript is thread-safe but provides no threading locking mechanism to the script
|
||||||
ChaiScript &add_global(const Boxed_Value &t_bv, const std::string &t_name)
|
ChaiScript &add_global(const Boxed_Value &t_bv, const std::string &t_name)
|
||||||
{
|
{
|
||||||
m_engine.add_global(t_bv, t_name);
|
m_engine.add_global(t_bv, t_name);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChaiScript &set_global(const Boxed_Value &t_bv, const std::string &t_name)
|
ChaiScript &set_global(const Boxed_Value &t_bv, const std::string &t_name)
|
||||||
{
|
{
|
||||||
m_engine.set_global(t_bv, t_name);
|
m_engine.set_global(t_bv, t_name);
|
||||||
return *this;
|
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
|
||||||
/// \warning State object does not contain the user defined type conversions of the engine. They
|
/// \warning State object does not contain the user defined type conversions of the engine. They
|
||||||
/// are left out due to performance considerations involved in tracking the state
|
/// are left out due to performance considerations involved in tracking the state
|
||||||
/// \sa ChaiScript::get_state
|
/// \sa ChaiScript::get_state
|
||||||
|
Loading…
x
Reference in New Issue
Block a user