Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 1.08 KB | None | 0 0
  1. //Ext.cpp class
  2. #include <iostream>
  3.  
  4. class Ext
  5. {
  6.   public:
  7.     Ext(int init){
  8.         std::cout << "you made me\n";
  9.         b = init;
  10.     }
  11.  
  12.     void squawk()
  13.     {
  14.         std::cout << "hello ext\n";
  15.     }
  16.    
  17.     int adderize(int a)
  18.     {
  19.         b+=a;
  20.         std::cout << "b is now "<<b<<"\n";
  21.         return b;
  22.     }
  23.   private:
  24.     int b;
  25. };
  26.  
  27.  
  28. //Ext.hx class
  29.  
  30. package;
  31. import cpp.Pointer;
  32. @:include("./Ext.cpp")
  33. @:structAccess
  34.  
  35. extern class Ext
  36. {
  37.    
  38.     @:native("new Ext")
  39.     public static function create (init:Int) : Pointer<Ext>;
  40.    
  41.     @:native("squawk")
  42.     public function squawk():Void;
  43.    
  44.     @:native("adderize")
  45.     public function adderize(a:Int):Int;
  46.    
  47.     public function bleet():Void{
  48.         trace("I'm a real boy!");
  49.     }
  50. }
  51.  
  52. //Main.hx
  53. package;
  54. class Main
  55. {
  56.    
  57.     static function main()
  58.     {
  59.         var ext = Ext.create(35);   //you made me
  60.         var myext = ext.get_ref();  
  61.         myext.squawk();             //hello ext
  62.         trace(myext.adderize(2));   //b is now 37 \n Main.hx:16:37
  63.         //myext.bleet();            //uncomment for compile error: ./src/Main.cpp(42): error C2039: 'bleet': is not a member of 'Ext'
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement