Advertisement
Xliff

Going NativeCall.... *sigh*

Apr 3rd, 2016
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.90 KB | None | 0 0
  1. use NativeCall;
  2.  
  3. class TestStruct_s is repr<CPointer> {
  4.         has Int         $!t;
  5.         has Pointer     $!tp;
  6.         has Str         $!s;
  7.  
  8.         method print_T {
  9.                 say $!t;
  10.         }
  11. }
  12.  
  13. class TestStruct_I_s is repr<CPointer> {
  14.         has TestStruct_s        $!cts_V;
  15.         has TestStruct_s        $!cts_I;
  16.         has TestStruct_s        $!cts_IP;
  17.         has TestStruct_s        $!cts_S;
  18.  
  19.         method cts_V {
  20.                 $!cts_V();
  21.         }
  22.  
  23.         method cts_I(Int $i) {
  24.                 my &func_sig = nativecast(:(Int --> TestStruct_s), $!cts_I);
  25.  
  26.                 return &func_sig($i);
  27.         }
  28. }
  29.  
  30.  
  31. sub createTestStruct()
  32.         is native('libtest') returns TestStruct_I_s
  33.         { * };
  34.  
  35. sub main {
  36.         my $tsi = createTestStruct();
  37.  
  38.         my $ts = $tsi.cts_I(4);
  39.         say $ts.WHAT;
  40.         say $ts.print_T;
  41.         say "DONE!";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement