Add test for constructing from a pointer return value and fix test so it works. Task #13

This commit is contained in:
Jason Turner
2011-09-09 14:38:55 -06:00
parent 2b64c90a0e
commit e326fe6f2d
2 changed files with 18 additions and 0 deletions

View File

@@ -34,6 +34,15 @@ namespace chaiscript
} }
}; };
template<typename Ret>
struct Handle_Return<Ret *>
{
static Boxed_Value handle(Ret *p)
{
return Boxed_Value(p);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<boost::shared_ptr<Ret> &> struct Handle_Return<boost::shared_ptr<Ret> &>
{ {

View File

@@ -7,6 +7,7 @@ class TestBaseType
public: public:
TestBaseType() {} TestBaseType() {}
TestBaseType(int) {} TestBaseType(int) {}
TestBaseType(int *) {}
virtual ~TestBaseType() {} virtual ~TestBaseType() {}
virtual int func() { return 0; } virtual int func() { return 0; }
@@ -24,6 +25,11 @@ std::string hello_world()
return "Hello World"; return "Hello World";
} }
int *get_new_int()
{
return new int(1);
}
// MSVC doesn't like that we are using C++ return types from our C declared module // MSVC doesn't like that we are using C++ return types from our C declared module
// but this is the best way to do it for cross platform compatibility // but this is the best way to do it for cross platform compatibility
#ifdef BOOST_MSVC #ifdef BOOST_MSVC
@@ -44,6 +50,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
m->add(chaiscript::constructor<TestBaseType ()>(), "TestBaseType"); m->add(chaiscript::constructor<TestBaseType ()>(), "TestBaseType");
// m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType"); // m->add(chaiscript::constructor<TestBaseType (int)>(), "TestBaseType");
m->add(chaiscript::constructor<TestBaseType (const TestBaseType &)>(), "TestBaseType"); m->add(chaiscript::constructor<TestBaseType (const TestBaseType &)>(), "TestBaseType");
m->add(chaiscript::constructor<TestBaseType (int *)>(), "TestBaseType");
m->add(chaiscript::constructor<TestDerivedType ()>(), "TestDerivedType"); m->add(chaiscript::constructor<TestDerivedType ()>(), "TestDerivedType");
m->add(chaiscript::constructor<TestDerivedType (const TestDerivedType &)>(), "TestDerivedType"); m->add(chaiscript::constructor<TestDerivedType (const TestDerivedType &)>(), "TestDerivedType");
@@ -52,6 +59,8 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
m->add(chaiscript::fun(&TestBaseType::func), "func"); m->add(chaiscript::fun(&TestBaseType::func), "func");
m->add(chaiscript::fun(&get_new_int), "get_new_int");
return m; return m;
} }