Created
February 8, 2015 17:38
-
-
Save FROGGS/7c8180851f3b89821631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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