Compare commits
10 Commits
Release-2.
...
Release-2.
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d8213a4206 | ||
![]() |
3a4421a57c | ||
![]() |
31fec2202c | ||
![]() |
13178e55e1 | ||
![]() |
968da650b2 | ||
![]() |
fb5ba0be26 | ||
![]() |
39a2c39d90 | ||
![]() |
70047424f9 | ||
![]() |
2805af1ed2 | ||
![]() |
e5a29ede5f |
@@ -4,7 +4,7 @@
|
|||||||
#ifndef CHAISCRIPT_NO_THREADS
|
#ifndef CHAISCRIPT_NO_THREADS
|
||||||
#include <boost/thread.hpp>
|
#include <boost/thread.hpp>
|
||||||
#else
|
#else
|
||||||
#warning "ChaiScript is compiling without thread safety."
|
#pragma message ("ChaiScript is compiling without thread safety.")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
|
@@ -35,14 +35,14 @@ namespace chaiscript
|
|||||||
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
|
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
|
||||||
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o)
|
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param)), const O &o)
|
||||||
{
|
{
|
||||||
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ret, typename O, typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
template<typename Ret, typename O, typename Class BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
|
||||||
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
|
boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))>
|
||||||
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const O &o)
|
bind_first(Ret (Class::*f)(BOOST_PP_ENUM_PARAMS(n, Param))const, const O &o)
|
||||||
{
|
{
|
||||||
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
return boost::bind(boost::mem_fn(f), o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Ret,typename O BOOST_PP_COMMA_IF(m) BOOST_PP_ENUM_PARAMS(m, typename Param) >
|
template<typename Ret,typename O BOOST_PP_COMMA_IF(m) BOOST_PP_ENUM_PARAMS(m, typename Param) >
|
||||||
@@ -58,8 +58,9 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
return boost::bind(f, o BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM(n, param, _));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef n
|
||||||
|
#undef m
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -134,7 +134,7 @@ namespace chaiscript
|
|||||||
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
|
//In the interest of runtime safety for the m, we prefer the at() method for [] access,
|
||||||
//to throw an exception in an out of bounds condition.
|
//to throw an exception in an out of bounds condition.
|
||||||
m->add(
|
m->add(
|
||||||
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(static_cast<indexoper>(&ContainerType::at))), "[]");
|
fun(boost::function<typename ContainerType::reference (ContainerType *, int)>(boost::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ namespace chaiscript
|
|||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
m->add(fun(boost::function<int (const ContainerType *)>(&ContainerType::size)), "size");
|
m->add(fun(boost::function<int (const ContainerType *)>(boost::mem_fn(&ContainerType::size))), "size");
|
||||||
m->add(fun<bool (ContainerType::*)() const>(&ContainerType::empty), "empty");
|
m->add(fun<bool (ContainerType::*)() const>(&ContainerType::empty), "empty");
|
||||||
m->add(fun<void (ContainerType::*)()>(&ContainerType::clear), "clear");
|
m->add(fun<void (ContainerType::*)()>(&ContainerType::clear), "clear");
|
||||||
|
|
||||||
@@ -252,7 +252,8 @@ namespace chaiscript
|
|||||||
push_back_name = "push_back";
|
push_back_name = "push_back";
|
||||||
}
|
}
|
||||||
|
|
||||||
m->add(fun(&ContainerType::push_back), push_back_name);
|
typedef void (ContainerType::*pushback)(const typename ContainerType::value_type &);
|
||||||
|
m->add(fun(static_cast<pushback>(&ContainerType::push_back)), push_back_name);
|
||||||
m->add(fun(&ContainerType::pop_back), "pop_back");
|
m->add(fun(&ContainerType::pop_back), "pop_back");
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -319,8 +320,7 @@ namespace chaiscript
|
|||||||
template<typename ContainerType>
|
template<typename ContainerType>
|
||||||
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
// m->add(fun<size_t (ContainerType::*)(const typename ContainerType::key_type &) const>(&ContainerType::count), "count");
|
m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(boost::mem_fn(&ContainerType::count))), "count");
|
||||||
m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(&ContainerType::count)), "count");
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -333,7 +333,9 @@ namespace chaiscript
|
|||||||
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
m->add(user_type<MapType>(), type);
|
m->add(user_type<MapType>(), type);
|
||||||
m->add(fun(&MapType::operator[]), "[]");
|
|
||||||
|
typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &);
|
||||||
|
m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");
|
||||||
|
|
||||||
container_type<MapType>(type, m);
|
container_type<MapType>(type, m);
|
||||||
assignable_type<MapType>(type, m);
|
assignable_type<MapType>(type, m);
|
||||||
@@ -384,7 +386,6 @@ namespace chaiscript
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a String container
|
* Add a String container
|
||||||
* http://www.sgi.com/tech/stl/basic_string.html
|
* http://www.sgi.com/tech/stl/basic_string.html
|
||||||
@@ -417,12 +418,12 @@ namespace chaiscript
|
|||||||
|
|
||||||
typedef boost::function<int (const String *, const String &, int)> find_func;
|
typedef boost::function<int (const String *, const String &, int)> find_func;
|
||||||
|
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find))), "find");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find)))), "find");
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::rfind))), "rfind");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::rfind)))), "rfind");
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_first_of))), "find_first_of");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_first_of)))), "find_first_of");
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_last_of))), "find_last_of");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_last_of)))), "find_last_of");
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_first_not_of))), "find_first_not_of");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_first_not_of)))), "find_first_not_of");
|
||||||
m->add(fun(find_func(static_cast<find_func_ptr>(&String::find_last_not_of))), "find_last_not_of");
|
m->add(fun(find_func(boost::mem_fn(static_cast<find_func_ptr>(&String::find_last_not_of)))), "find_last_not_of");
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/cstdint.hpp>
|
#include <boost/cstdint.hpp>
|
||||||
#include <boost/type_traits/add_const.hpp>
|
#include <boost/type_traits/add_const.hpp>
|
||||||
#include <limits>
|
#include <boost/integer_traits.hpp>
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
@@ -818,8 +818,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
Boxed_Value smart_size(boost::int64_t i) const
|
Boxed_Value smart_size(boost::int64_t i) const
|
||||||
{
|
{
|
||||||
if (i < std::numeric_limits<int>::min()
|
if (i < boost::integer_traits<int>::const_min
|
||||||
|| i > std::numeric_limits<int>::max())
|
|| i > boost::integer_traits<int>::const_max)
|
||||||
{
|
{
|
||||||
return Boxed_Value(i);
|
return Boxed_Value(i);
|
||||||
} else {
|
} else {
|
||||||
@@ -905,13 +905,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std
|
|
||||||
{
|
|
||||||
template<> void swap(chaiscript::Boxed_Value &lhs, chaiscript::Boxed_Value &rhs)
|
|
||||||
{
|
|
||||||
lhs.swap(rhs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -93,6 +93,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#undef n
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#undef n
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -130,4 +130,6 @@ namespace chaiscript
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef n
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -14,12 +14,13 @@
|
|||||||
#include <boost/function_types/components.hpp>
|
#include <boost/function_types/components.hpp>
|
||||||
#include <boost/function_types/function_type.hpp>
|
#include <boost/function_types/function_type.hpp>
|
||||||
#include <boost/function_types/is_member_object_pointer.hpp>
|
#include <boost/function_types/is_member_object_pointer.hpp>
|
||||||
|
#include <boost/function_types/is_member_function_pointer.hpp>
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
template<bool Object>
|
template<bool Object, bool MemFn>
|
||||||
struct Fun_Helper
|
struct Fun_Helper
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -32,10 +33,26 @@ namespace chaiscript
|
|||||||
typename boost::function_types::function_type<boost::function_types::components<T> >::type
|
typename boost::function_types::function_type<boost::function_types::components<T> >::type
|
||||||
>(t)));
|
>(t)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Fun_Helper<true>
|
struct Fun_Helper<false, true>
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
static Proxy_Function go(T t)
|
||||||
|
{
|
||||||
|
return Proxy_Function(
|
||||||
|
new Proxy_Function_Impl<
|
||||||
|
typename boost::function_types::function_type<boost::function_types::components<T> >::type> (
|
||||||
|
boost::function<
|
||||||
|
typename boost::function_types::function_type<boost::function_types::components<T> >::type
|
||||||
|
>(boost::mem_fn(t))));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Fun_Helper<true, false>
|
||||||
{
|
{
|
||||||
template<typename T, typename Class>
|
template<typename T, typename Class>
|
||||||
static Proxy_Function go(T Class::* m)
|
static Proxy_Function go(T Class::* m)
|
||||||
@@ -55,7 +72,7 @@ namespace chaiscript
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
Proxy_Function fun(T t)
|
Proxy_Function fun(T t)
|
||||||
{
|
{
|
||||||
return detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value>::go(t);
|
return detail::Fun_Helper<boost::function_types::is_member_object_pointer<T>::value, boost::function_types::is_member_function_pointer<T>::value>::go(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Q>
|
template<typename T, typename Q>
|
||||||
|
@@ -345,12 +345,14 @@ namespace chaiscript
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Boxed_Value retval = ss.call_function("Vector");
|
Boxed_Value retval = ss.call_function("Vector");
|
||||||
for (i = 0; i < node->children[0]->children.size(); ++i) {
|
if (node->children.size() > 0) {
|
||||||
try {
|
for (i = 0; i < node->children[0]->children.size(); ++i) {
|
||||||
ss.call_function("push_back", retval, eval_token(ss, node->children[0]->children[i]));
|
try {
|
||||||
}
|
ss.call_function("push_back", retval, eval_token(ss, node->children[0]->children[i]));
|
||||||
catch (const dispatch_error &) {
|
}
|
||||||
throw Eval_Error("Can not find appropriate 'push_back'", node->children[0]->children[i]);
|
catch (const dispatch_error &) {
|
||||||
|
throw Eval_Error("Can not find appropriate 'push_back'", node->children[0]->children[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -275,6 +275,38 @@ namespace chaiscript
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a floating point value from input, without skipping initial whitespace
|
||||||
|
*/
|
||||||
|
bool Binary_() {
|
||||||
|
bool retval = false;
|
||||||
|
if ((input_pos != input_end) && (*input_pos == '0')) {
|
||||||
|
++input_pos;
|
||||||
|
++col;
|
||||||
|
|
||||||
|
if ((input_pos != input_end) && ((*input_pos == 'b') || (*input_pos == 'B'))) {
|
||||||
|
++input_pos;
|
||||||
|
++col;
|
||||||
|
if ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
|
||||||
|
retval = true;
|
||||||
|
while ((input_pos != input_end) && ((*input_pos >= '0') && (*input_pos <= '1'))) {
|
||||||
|
++input_pos;
|
||||||
|
++col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
--input_pos;
|
||||||
|
--col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
--input_pos;
|
||||||
|
--col;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a number from the input, detecting if it's an integer or floating point
|
* Reads a number from the input, detecting if it's an integer or floating point
|
||||||
@@ -293,9 +325,28 @@ namespace chaiscript
|
|||||||
if (Hex_()) {
|
if (Hex_()) {
|
||||||
std::string match(start, input_pos);
|
std::string match(start, input_pos);
|
||||||
std::stringstream ss(match);
|
std::stringstream ss(match);
|
||||||
int temp_int;
|
unsigned int temp_int;
|
||||||
ss >> std::hex >> temp_int;
|
ss >> std::hex >> temp_int;
|
||||||
|
|
||||||
|
std::ostringstream out_int;
|
||||||
|
out_int << int(temp_int);
|
||||||
|
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
|
||||||
|
match_stack.push_back(t);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (Binary_()) {
|
||||||
|
std::string match(start, input_pos);
|
||||||
|
int temp_int = 0;
|
||||||
|
unsigned int pos = 0, end = match.length();
|
||||||
|
|
||||||
|
while ((pos < end) && (pos < (2 + sizeof(int) * 8))) {
|
||||||
|
temp_int <<= 1;
|
||||||
|
if (match[pos] == '1') {
|
||||||
|
temp_int += 1;
|
||||||
|
}
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostringstream out_int;
|
std::ostringstream out_int;
|
||||||
out_int << temp_int;
|
out_int << temp_int;
|
||||||
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
|
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
|
||||||
@@ -312,11 +363,11 @@ namespace chaiscript
|
|||||||
std::string match(start, input_pos);
|
std::string match(start, input_pos);
|
||||||
if ((match.size() > 0) && (match[0] == '0')) {
|
if ((match.size() > 0) && (match[0] == '0')) {
|
||||||
std::stringstream ss(match);
|
std::stringstream ss(match);
|
||||||
int temp_int;
|
unsigned int temp_int;
|
||||||
ss >> std::oct >> temp_int;
|
ss >> std::oct >> temp_int;
|
||||||
|
|
||||||
std::ostringstream out_int;
|
std::ostringstream out_int;
|
||||||
out_int << temp_int;
|
out_int << int(temp_int);
|
||||||
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
|
TokenPtr t(new Token(out_int.str(), Token_Type::Int, filename, prev_line, prev_col, line, col));
|
||||||
match_stack.push_back(t);
|
match_stack.push_back(t);
|
||||||
}
|
}
|
||||||
|
@@ -144,7 +144,7 @@ int main(int argc, char *argv[]) {
|
|||||||
log("Functor test output", boost::lexical_cast<std::string>(x));
|
log("Functor test output", boost::lexical_cast<std::string>(x));
|
||||||
|
|
||||||
chai.add(var(boost::shared_ptr<int>()), "nullvar");
|
chai.add(var(boost::shared_ptr<int>()), "nullvar");
|
||||||
chai("print(\"This should be true.\"); print(nullvar.is_null())");
|
chai("print(\"This should be true.\"); print(nullvar.is_var_null())");
|
||||||
|
|
||||||
// test the global const action
|
// test the global const action
|
||||||
chai.add_global_const(const_var(1), "constvar");
|
chai.add_global_const(const_var(1), "constvar");
|
||||||
@@ -168,8 +168,8 @@ int main(int argc, char *argv[]) {
|
|||||||
chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr");
|
chai.add(fun(boost::function<Boxed_Value (Dynamic_Object &)>(boost::bind(&Dynamic_Object_Attribute::func, "TestType", "attr", _1))), "attr");
|
||||||
|
|
||||||
chai.eval("var x = TestType()");
|
chai.eval("var x = TestType()");
|
||||||
chai.eval("x.attr = \"hi\"");
|
// chai.eval("x.attr = \"hi\"");
|
||||||
chai.eval("print(x.attr)");
|
// chai.eval("print(x.attr)");
|
||||||
chai.eval("x.hello_world()");
|
chai.eval("x.hello_world()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
unittests/vector_push_empty.chai
Normal file
3
unittests/vector_push_empty.chai
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
var bob = []
|
||||||
|
bob.push_back(3)
|
||||||
|
print(bob)
|
1
unittests/vector_push_empty.txt
Normal file
1
unittests/vector_push_empty.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[3]
|
Reference in New Issue
Block a user