Skip to content

Instantly share code, notes, and snippets.

@scovit
Created May 12, 2020 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scovit/8d2e0254fdc2a5ef59fc38a177a5fe03 to your computer and use it in GitHub Desktop.
Save scovit/8d2e0254fdc2a5ef59fc38a177a5fe03 to your computer and use it in GitHub Desktop.
use NativeCall;
class IntStruct is repr('CStruct') {
has int32 $.first;
has int32 $.second;
}
class StructIntStruct is repr('CStruct') {
HAS IntStruct $.a;
has int32 $.i;
submethod TWEAK(:$first = 0, :$second = 0, :$i) {
$!a := IntStruct.new(:$first, :$second);
$!i = $i;
}
}
my $a = StructIntStruct.new(:12first, :11second, :3i);
say $a.a.first;
say $a.a.second;
say $a.i;
my $ptr = nativecast(CArray[int32], $a);
say $ptr[0];
say $ptr[1];
say $ptr[2];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment