Merge branch 'master' into ChaiScript_5_0_CPP_11
Conflicts: include/chaiscript/dispatchkit/bootstrap_stl.hpp include/chaiscript/dispatchkit/boxed_number.hpp
This commit is contained in:
@@ -519,6 +519,31 @@ namespace chaiscript
|
||||
return m;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename String>
|
||||
struct apple_string_workarounds
|
||||
{
|
||||
/// The latest version of MacOS has a broken std::string implementation which will not allow
|
||||
/// us to take pointers to the members. Code compiles, but does not link
|
||||
/// \todo re-evaluate at some point
|
||||
|
||||
static size_t find(const String *s, const String &w, int pos) { return s->find(w, pos); }
|
||||
static size_t rfind(const String *s, const String &w, size_t pos) { return s->rfind(w, pos); }
|
||||
static size_t find_first_of(const String *s, const String &w, size_t pos) { return s->find_first_of(w, pos); }
|
||||
static size_t find_last_of(const String *s, const String &w, size_t pos) { return s->find_last_of(w, pos); }
|
||||
static size_t find_first_not_of(const String *s, const String &w, size_t pos) { return s->find_first_not_of(w, pos); }
|
||||
static size_t find_last_not_of(const String *s, const String &w, size_t pos) { return s->find_last_not_of(w, pos); }
|
||||
|
||||
static void clear(String *s) { s->clear(); }
|
||||
static bool empty(const String *s) { return s->empty(); }
|
||||
static size_t size(const String *s) { return s->size(); }
|
||||
|
||||
static std::string substr(const String *s, size_t pos, size_t len) { return s->substr(pos,len); }
|
||||
static const char *c_str(const String *s) { return s->c_str(); }
|
||||
static const char *data(const String *s) { return s->data(); }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a String container
|
||||
* http://www.sgi.com/tech/stl/basic_string.html
|
||||
@@ -533,7 +558,7 @@ namespace chaiscript
|
||||
random_access_container_type<String>(type, m);
|
||||
sequence_type<String>(type, m);
|
||||
default_constructible_type<String>(type, m);
|
||||
container_type<String>(type, m);
|
||||
// container_type<String>(type, m);
|
||||
assignable_type<String>(type, m);
|
||||
input_range_type<String>(type, m);
|
||||
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#include <sstream>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace chaiscript
|
||||
{
|
||||
|
||||
|
@@ -53,9 +53,31 @@ namespace chaiscript
|
||||
|
||||
private:
|
||||
std::string m_word;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Exception thrown in the case that an object name is invalid because it contains illegal characters
|
||||
*/
|
||||
class illegal_name_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
illegal_name_error(const std::string &t_name) throw()
|
||||
: std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~illegal_name_error() throw() {}
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Exception thrown in the case that an object name is invalid because it already exists in current context
|
||||
*/
|
||||
@@ -483,6 +505,25 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new global (non-const) shared object, between all the threads
|
||||
*/
|
||||
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 chaiscript::exception::name_conflict_error(name);
|
||||
} else {
|
||||
m_state.m_global_objects.insert(std::make_pair(name, obj));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a new scope to the stack
|
||||
*/
|
||||
@@ -1102,6 +1143,10 @@ namespace chaiscript
|
||||
*/
|
||||
void validate_object_name(const std::string &name) const
|
||||
{
|
||||
if (name.find("::") != std::string::npos) {
|
||||
throw chaiscript::exception::illegal_name_error(name);
|
||||
}
|
||||
|
||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||
|
||||
if (m_state.m_reserved_words.find(name) != m_state.m_reserved_words.end())
|
||||
|
Reference in New Issue
Block a user