diff --git a/src/test_module.cpp b/src/test_module.cpp index 83cbc12e..13298c8d 100644 --- a/src/test_module.cpp +++ b/src/test_module.cpp @@ -11,6 +11,8 @@ class TestBaseType virtual ~TestBaseType() {} virtual int func() { return 0; } + int base_only_func() { return -9; } + const TestBaseType &constMe() const { return *this; } int val; @@ -41,11 +43,22 @@ class TestDerivedType : public TestBaseType TestDerivedType &operator=(const TestDerivedType &); }; +class TestMoreDerivedType : public TestDerivedType +{ + public: + virtual ~TestMoreDerivedType() {} +}; + boost::shared_ptr derived_type_factory() { return boost::shared_ptr(new TestDerivedType()); } +boost::shared_ptr more_derived_type_factory() +{ + return boost::shared_ptr(new TestMoreDerivedType()); +} + std::string hello_world() { return "Hello World"; @@ -76,6 +89,7 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo m->add(chaiscript::user_type(), "TestBaseType"); m->add(chaiscript::user_type(), "TestDerivedType"); + m->add(chaiscript::user_type(), "TestMoreDerivedType"); m->add(chaiscript::constructor(), "TestBaseType"); // m->add(chaiscript::constructor(), "TestBaseType"); @@ -85,15 +99,23 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo m->add(chaiscript::constructor(), "TestDerivedType"); m->add(chaiscript::constructor(), "TestDerivedType"); + m->add(chaiscript::constructor(), "TestMoreDerivedType"); + m->add(chaiscript::constructor(), "TestMoreDerivedType"); + + /// \todo automatic chaining of base classes? m->add(chaiscript::base_class()); + m->add(chaiscript::base_class()); + m->add(chaiscript::base_class()); m->add(chaiscript::fun(&TestDerivedType::derived_only_func), "derived_only_func"); m->add(chaiscript::fun(&derived_type_factory), "derived_type_factory"); + m->add(chaiscript::fun(&more_derived_type_factory), "more_derived_type_factory"); m->add(chaiscript::fun(&TestBaseType::func), "func"); m->add(chaiscript::fun(&TestBaseType::val), "val"); m->add(chaiscript::fun(&TestBaseType::const_val), "const_val"); + m->add(chaiscript::fun(&TestBaseType::base_only_func), "base_only_func"); m->add(chaiscript::fun(&get_new_int), "get_new_int"); diff --git a/unittests/inheritance.chai b/unittests/inheritance.chai index 99cf7c06..34df9d95 100644 --- a/unittests/inheritance.chai +++ b/unittests/inheritance.chai @@ -25,3 +25,11 @@ assert_equal(t.derived_only_func(), 19); var d := derived_type_factory(); assert_equal(d.derived_only_func(), 19); +var t2 = TestMoreDerivedType(); +assert_equal(t2.derived_only_func(), 19); +assert_equal(t2.base_only_func(), -9); + +var md := more_derived_type_factory(); +assert_equal(md.derived_only_func(), 19); +assert_equal(md.base_only_func(), -9); +