Advertisement
donkaban

js bind test

Sep 16th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include "js_host.h"
  2. #include "js_class.h"
  3.  
  4. ///////////////////////////////////////// test class for binding
  5.  
  6. struct A
  7. {
  8.    
  9.     A(xstr s)
  10.         : tag(s)
  11.     {std::cout << "A::A(" << tag << ")" << std::endl;}
  12.    
  13.     virtual ~A()            
  14.     {
  15.         std::cout << "A::~A [" << tag << "]" << std::endl;
  16.     }
  17.  
  18.     void f1(int i) {std::cout << "A::f1(" << i << ")" << " -> "<< tag <<std::endl;}
  19.     void f2(int i) {std::cout << "A::f2(" << i << ")" << " -> "<< tag <<std::endl;}
  20.     void f3(int i) {std::cout << "A::f3(" << i << ")" << " -> "<< tag <<std::endl;}
  21.  
  22.     int m1;
  23.     int m2;
  24.     int m3;
  25.  
  26.     static void s1(int i) {std::cout << "A::s1(" << i << ")"<< std::endl;}
  27.     static void s2(int i) {std::cout << "A::s2(" << i << ")"<< std::endl;}
  28.  
  29. private:
  30.     std::string  tag;
  31. };
  32.  
  33.  
  34. int main(int argc, char **argv)
  35. {
  36.     JSHost host ("oop");
  37.    
  38.     JSClass<A> cls("A");
  39.     cls
  40.         .ctor<xstr>   ()
  41.  
  42.         .meth<int> ("f1", &A::f1)
  43.         .meth<int> ("f2", &A::f2)
  44.         .meth<int> ("s1", &A::s1)
  45.         .meth<int> ("s2", &A::s2)
  46.  
  47.         .meth<int> ("xxx",  [&](int i) {std::cout << "statix xxx(" << i <<")\n";});
  48.  
  49.  
  50.     cls.bind(host);
  51.     host.ExecuteFile("js_tests/test.js");
  52.  
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement