aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChad Austin <chad@imvu.com>2013-12-06 16:35:47 -0800
committerBruce Mitchener <bruce.mitchener@gmail.com>2014-02-04 16:21:54 +0700
commit9ba56d2c20fb2a5d5572e6030bd9dc1794fefdd2 (patch)
treec74d388a3e78122bd42d73016624b1168570f492 /tests
parent52e04b489962f1167868aa46eb8325df4b2c9fdf (diff)
Add a sample for adding mixins to embind
Diffstat (limited to 'tests')
-rw-r--r--tests/embind/embind.test.js9
-rw-r--r--tests/embind/embind_test.cpp31
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/embind/embind.test.js b/tests/embind/embind.test.js
index 0976c597..a36c8b08 100644
--- a/tests/embind/embind.test.js
+++ b/tests/embind/embind.test.js
@@ -1916,6 +1916,15 @@ module({
sh1.delete();
});
});
+
+ BaseFixture.extend("mixin", function() {
+ test("can call mixin method", function() {
+ var a = new cm.DerivedWithMixin();
+ assert.instanceof(a, cm.Base);
+ assert.equal(10, a.get10());
+ a.delete();
+ });
+ });
});
/* global run_all_tests */
diff --git a/tests/embind/embind_test.cpp b/tests/embind/embind_test.cpp
index 508fe052..4efc4bd8 100644
--- a/tests/embind/embind_test.cpp
+++ b/tests/embind/embind_test.cpp
@@ -2273,3 +2273,34 @@ EMSCRIPTEN_BINDINGS(return_values) {
function("return_StringHolder_copy", &return_StringHolder_copy);
function("call_StringHolder_func", &call_StringHolder_func);
}
+
+
+struct Mixin {
+ int get10() const {
+ return 10;
+ }
+};
+
+template<typename ClassBinding>
+const ClassBinding& registerMixin(const ClassBinding& binding) {
+ // need a wrapper for implicit conversion from DerivedWithMixin to Mixin
+ struct Local {
+ static int get10(const typename ClassBinding::class_type& self) {
+ return self.get10();
+ }
+ };
+
+ return binding
+ .function("get10", &Local::get10)
+ ;
+}
+
+class DerivedWithMixin : public Base, public Mixin {
+};
+
+EMSCRIPTEN_BINDINGS(mixins) {
+ registerMixin(
+ class_<DerivedWithMixin, base<Base>>("DerivedWithMixin")
+ .constructor<>()
+ );
+}