File size: 595 Bytes
00df61d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <emscripten/bind.h>
#include <iostream>
#include <memory>

class Foo {
  std::string mName;

public:
  Foo(std::string name) : mName(name) {}
  ~Foo() { std::cout << mName << " destructed" << std::endl; }
};

std::shared_ptr<Foo> foo() {
  return std::make_shared<Foo>("Constructed from C++");
}

Foo* pFoo() { return new Foo("Foo*"); }

using namespace emscripten;

EMSCRIPTEN_BINDINGS(Marci) {
  class_<Foo>("Foo").smart_ptr_constructor<std::shared_ptr<Foo>>(
    "Foo", &std::make_shared<Foo, std::string>);

  function("foo", foo);
  function("pFoo", pFoo, allow_raw_pointers());
}