Skip to content

Instantly share code, notes, and snippets.

@FROGGS
Created February 8, 2015 17:38
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 FROGGS/7c8180851f3b89821631 to your computer and use it in GitHub Desktop.
Save FROGGS/7c8180851f3b89821631 to your computer and use it in GitHub Desktop.
use v6;
use NativeCall;
use Test;
class b2Vec2 is repr<CStruct> { }
my role NativeCallSymbol[Str $name] {
method native_symbol() { $name }
}
multi trait_mod:<is>(Routine $r, :$cppsym!) {
my $mangled = '_ZN'
~ $cppsym.split('::').map({$_.chars ~ $_}).join('')
~ 'EPK';
for $r.signature.params».type {
when int32 {
$mangled ~= 'i'
}
default {
my $name = .^name;
$mangled ~= $name.chars ~ $name;
}
}
$r does NativeCallSymbol[$mangled];
}
sub foo(b2Vec2, int32) is native("libBox2D") is cppsym<b2PolygonShape::Set> { * } # _ZN14b2PolygonShape3SetEPK6b2Vec2i
foo(b2Vec2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment