1. embind class

5337 단어
 1 #include 
 2 #include <string>
 3 
 4 using namespace std;
 5 using namespace emscripten;
 6 
 7 class xClass {
 8 public:
 9     //
10     xClass (int x, string y): x(x), y(y) {}
11 
12     //
13     void incrementX () {
14         x += 1;
15     }
16 
17     // [GETTER]
18     int getValueX () const {
19         return x;
20     }    
21     // [SETTER]
22     void setValueX (int val) {
23         x = val;
24     }
25 
26     //
27     static string getStringValue (const xClass& instance) {
28         return instance.y;
29     }
30 
31 private:
32     int x;
33     string y;
34 };
35 
36 EMSCRIPTEN_BINDINGS(module) {
37     class_("xClass")
38         .constructor<int, string>()
39         .function("incrementX", &xClass::incrementX)
40         .property("x", &xClass::getValueX, &xClass::setValueX)
41         .class_function("getStringValue", &xClass::getStringValue);
42 }

좋은 웹페이지 즐겨찾기