Add generic vector support and example code for working with
This commit is contained in:
parent
0ae57833aa
commit
2fa615974c
@ -240,6 +240,7 @@ void bootstrap(BoxedCPP_System &s)
|
||||
add_basic_constructors<bool>(s, "bool");
|
||||
add_basic_constructors<std::string>(s, "string");
|
||||
|
||||
s.register_function(build_constructor<int, unsigned int>(), "int");
|
||||
|
||||
|
||||
|
||||
|
@ -59,7 +59,6 @@ class Boxed_Value
|
||||
bool m_is_ref;
|
||||
};
|
||||
|
||||
|
||||
//cast_help specializations
|
||||
template<typename Result>
|
||||
struct Cast_Helper
|
||||
@ -131,5 +130,16 @@ struct Cast_Helper<Result &>
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Cast_Helper<Boxed_Value>
|
||||
{
|
||||
Boxed_Value operator()(Boxed_Value ob)
|
||||
{
|
||||
return ob;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -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();
|
||||
|
@ -35,6 +35,24 @@ struct Handle_Return<Ret &>
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Handle_Return<Boxed_Value>
|
||||
{
|
||||
Boxed_Value operator()(const boost::function<Boxed_Value ()> &f)
|
||||
{
|
||||
return f();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Handle_Return<Boxed_Value &>
|
||||
{
|
||||
Boxed_Value operator()(const boost::function<Boxed_Value &()> &f)
|
||||
{
|
||||
return f();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Handle_Return<void>
|
||||
{
|
||||
|
16
samples/vector.wes
Normal file
16
samples/vector.wes
Normal file
@ -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
|
||||
}
|
@ -441,6 +441,7 @@ BoxedCPP_System build_eval_system() {
|
||||
BoxedCPP_System ss;
|
||||
bootstrap(ss);
|
||||
bootstrap_vector<std::vector<int> >(ss, "VectorInt");
|
||||
bootstrap_vector<std::vector<Boxed_Value> >(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<int>, "print");
|
||||
|
||||
ss.register_function(boost::function<void ()>(boost::bind(&dump_system, boost::ref(ss))), "dump_system");
|
||||
ss.register_function(boost::function<void (Boxed_Value)>(boost::bind(&dump_object, _1)), "dump_object");
|
||||
|
||||
|
||||
ss.register_function(boost::shared_ptr<Proxy_Function>(
|
||||
new Dynamic_Proxy_Function(boost::bind(&add_two, boost::ref(ss), _1), 2)), "add_two");
|
||||
|
Loading…
x
Reference in New Issue
Block a user