Permalink
Browse files

Add example of wrapping data members of a class #79

  • Loading branch information...
1 parent d068ce4 commit 185888501011601a2c4aff318939fa0f4f59892c @lefticus lefticus committed Feb 24, 2013
Showing with 18 additions and 3 deletions.
  1. +7 −3 src/test_module.cpp
  2. +9 −0 unittests/inheritance.chai
  3. +2 −0 unittests/load_module.chai
View
@@ -5,12 +5,14 @@
class TestBaseType
{
public:
- TestBaseType() {}
- TestBaseType(int) {}
- TestBaseType(int *) {}
+ TestBaseType() : val(10), const_val(15) { }
+ TestBaseType(int) : val(10), const_val(15) {}
+ TestBaseType(int *) : val(10), const_val(15) {}
virtual ~TestBaseType() {}
virtual int func() { return 0; }
+ int val;
+ const int const_val;
};
enum TestEnum
@@ -68,6 +70,8 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_test_mo
m->add(chaiscript::base_class<TestBaseType, TestDerivedType>());
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(&get_new_int), "get_new_int");
@@ -6,3 +6,12 @@ var t = TestDerivedType();
assert_equal(t0.func(), 0);
assert_equal(t.func(), 1);
+assert_equal(10, t0.val);
+assert_equal(15, t0.const_val);
+
+assert_equal(10, t.val);
+assert_equal(15, t.const_val);
+
+t.val = 23;
+assert_equal(23, t.val)
+
@@ -1,2 +1,4 @@
load_module("test_module")
assert_equal("Hello World", hello_world());
+
+

0 comments on commit 1858885

Please sign in to comment.