Skip to content

Instantly share code, notes, and snippets.

@xaxxon
Created February 5, 2016 11:55
Show Gist options
  • Save xaxxon/262dd835aae697c7132d to your computer and use it in GitHub Desktop.
Save xaxxon/262dd835aae697c7132d to your computer and use it in GitHub Desktop.
i->wrap_class<Child>().add_constructor("Child", i->get_object_template());
i->wrap_class<Parent>().add_constructor("Parent", i->get_object_template()).set_compatible_types<Child>();
i->wrap_class<NotFamily>().add_constructor("NotFamily", i->get_object_template());
i->add_function("parent", [](Parent * p) {
printf("In 'parent' function\n");
});
auto c = i->create_context();
c->run("parent(new Parent())");
c->run("parent(new Child())");
try {
c->run("parent(new NotFamily())");
printf("Didn't catch exception\n");
} catch(...) {
printf("Caught exception\n");
}
output:
In 'parent' function
In 'parent' function
Caught exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment