From 2fa615974c1f7c732b525b12e1c854f1b195aa6f Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 7 Jun 2009 15:54:07 +0000 Subject: [PATCH] Add generic vector support and example code for working with --- boxedcpp/bootstrap.hpp | 1 + boxedcpp/boxed_value.hpp | 12 +++++++++++- boxedcpp/boxedcpp.hpp | 5 +++++ boxedcpp/proxy_functions.hpp | 18 ++++++++++++++++++ samples/vector.wes | 16 ++++++++++++++++ wesley/main.cpp | 3 +++ 6 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 samples/vector.wes diff --git a/boxedcpp/bootstrap.hpp b/boxedcpp/bootstrap.hpp index d0811bc..bf92573 100644 --- a/boxedcpp/bootstrap.hpp +++ b/boxedcpp/bootstrap.hpp @@ -240,6 +240,7 @@ void bootstrap(BoxedCPP_System &s) add_basic_constructors(s, "bool"); add_basic_constructors(s, "string"); + s.register_function(build_constructor(), "int"); diff --git a/boxedcpp/boxed_value.hpp b/boxedcpp/boxed_value.hpp index 7d3c92f..2f39d47 100644 --- a/boxedcpp/boxed_value.hpp +++ b/boxedcpp/boxed_value.hpp @@ -59,7 +59,6 @@ class Boxed_Value bool m_is_ref; }; - //cast_help specializations template struct Cast_Helper @@ -131,5 +130,16 @@ struct Cast_Helper } }; +template<> +struct Cast_Helper +{ + Boxed_Value operator()(Boxed_Value ob) + { + return ob; + } +}; + + + #endif diff --git a/boxedcpp/boxedcpp.hpp b/boxedcpp/boxedcpp.hpp index e082297..03e3b15 100644 --- a/boxedcpp/boxedcpp.hpp +++ b/boxedcpp/boxedcpp.hpp @@ -124,6 +124,11 @@ class BoxedCPP_System Type_Name_Map m_types; }; +void dump_object(Boxed_Value o) +{ + std::cout << o.get_type_info().m_type_info->name() << std::endl; +} + void dump_type(const Type_Info &type) { std::cout << type.m_bare_type_info->name(); diff --git a/boxedcpp/proxy_functions.hpp b/boxedcpp/proxy_functions.hpp index 4758975..7d36d25 100644 --- a/boxedcpp/proxy_functions.hpp +++ b/boxedcpp/proxy_functions.hpp @@ -35,6 +35,24 @@ struct Handle_Return } }; +template<> +struct Handle_Return +{ + Boxed_Value operator()(const boost::function &f) + { + return f(); + } +}; + +template<> +struct Handle_Return +{ + Boxed_Value operator()(const boost::function &f) + { + return f(); + } +}; + template<> struct Handle_Return { diff --git a/samples/vector.wes b/samples/vector.wes new file mode 100644 index 0000000..a7268d7 --- /dev/null +++ b/samples/vector.wes @@ -0,0 +1,16 @@ +var vec = Vector() + +vec.push_back(5) +vec.push_back("Hello World") +vec.push_back(25.3) + + +var i = int(0) +var size = int(vec.size()) + +print("Vector Size: " + size.to_string()); + +while (i < size) { + print(i.to_string() + ": " + to_string(vec[i])) + i = i + 1 +} diff --git a/wesley/main.cpp b/wesley/main.cpp index e71f073..a1a7d68 100644 --- a/wesley/main.cpp +++ b/wesley/main.cpp @@ -441,6 +441,7 @@ BoxedCPP_System build_eval_system() { BoxedCPP_System ss; bootstrap(ss); bootstrap_vector >(ss, "VectorInt"); + bootstrap_vector >(ss, "Vector"); // dump_system(ss); //Register a new function, this one with typing for us, so we don't have to ubox anything @@ -453,6 +454,8 @@ BoxedCPP_System build_eval_system() { register_function(ss, &print, "print"); ss.register_function(boost::function(boost::bind(&dump_system, boost::ref(ss))), "dump_system"); + ss.register_function(boost::function(boost::bind(&dump_object, _1)), "dump_object"); + ss.register_function(boost::shared_ptr( new Dynamic_Proxy_Function(boost::bind(&add_two, boost::ref(ss), _1), 2)), "add_two");