Skip to content

Instantly share code, notes, and snippets.

@xaxxon
Created February 16, 2016 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xaxxon/49234d3921bacb6f4a72 to your computer and use it in GitHub Desktop.
Save xaxxon/49234d3921bacb6f4a72 to your computer and use it in GitHub Desktop.
class Animal {
public:
virtual ~Animal()=default;
string get_type() {return "Cow";}
virtual string get_name() {return "This is the c++ get_name";};
virtual string echo(string s){return s;}
virtual int add(int i, int j){return i + j;}
};
...
auto i = PlatformHelper::create_isolate();
(*i)([&]{
i->add_print();
auto & animal = i->wrap_class<Animal>(); // THESE 3 LINES ARE MY LIBRARY STUFF, BUT YOU CAN ENVISION WHAT THEY DO
animal.add_method(&Animal::get_type, "get_type").add_method(&Animal::get_name, "get_name");
animal.add_constructor("Animal", *i);
auto c = i->create_context();
c->run("a=new Animal();a.get_name();"); <=== This line works
c->run("b=Object.create(new Animal()); b.get_name();"); <== this line returns an internal field of nullptr in my callback for get_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment