#include #include #include #include #include #include "boxedcpp.hpp" struct Test { Test() : md(0) { } Test(const std::string &s) : message(s), md(0) { std::cout << "Test class constructed with value: " << s << std::endl; } void show_message() { std::cout << "Constructed Message: " << message << std::endl; } std::string &get_message() { return message; } int method(double d) { md += d; std::cout << "Method called " << md << std::endl; return int(md); } std::string message; double md; }; std::string testprint(const std::string &p) { std::cout << p << std::endl; return p; } void print() { std::cout << "Test void function succeeded" << std::endl; } //Test main int main() { BoxedCPP_System ss; bootstrap(ss); ss.register_type("Test"); ss.register_function(boost::function(&Test::method), "method"); ss.register_function(boost::function(&testprint), "print"); ss.register_function(boost::function(&print), "voidfunc"); ss.register_function(build_constructor(), "Test"); ss.register_function(boost::function(&Test::show_message), "show_message"); ss.register_function(boost::function(&Test::get_message), "get_message"); ss.add_object("testobj", boost::shared_ptr(new Test())); ss.add_object("d", boost::shared_ptr(new double(10.2))); ss.add_object("str", std::string("Hello World")); dump_system(ss); std::vector sos; sos.push_back(ss.get_object("testobj")); sos.push_back(ss.get_object("d")); boost::shared_ptr method1(ss.get_function("method").front().second); (*method1)(sos); (*method1)(sos); Boxed_Value o = (*method1)(sos); dispatch(ss.get_function("print"), Param_List_Builder() << ss.get_object("str")); //Add new dynamically created object from registered "Test" constructor ss.add_object("testobj2", dispatch(ss.get_function("Test"), Param_List_Builder() << std::string("Yo"))); std::cout << Cast_Helper()(o) << std::endl; dispatch(ss.get_function("voidfunc"), Param_List_Builder()); std::vector sos3; sos3.push_back(ss.get_object("testobj2")); dispatch(ss.get_function("show_message"), sos3); Boxed_Value stringref = dispatch(ss.get_function("get_message"), sos3); std::string &sr = Cast_Helper()(stringref); sr = "Bob Updated The message"; dispatch(ss.get_function("show_message"), sos3); }