Skip to content

Instantly share code, notes, and snippets.

@jnthn
Created November 22, 2011 23:18
Show Gist options
  • Save jnthn/1387382 to your computer and use it in GitHub Desktop.
Save jnthn/1387382 to your computer and use it in GitHub Desktop.
#include <stdio.h>
__declspec(dllexport) /* comment this line out if not on Windows */
int GotValues(int a, float b)
{
printf("Got %d\nGot %f\n", a, b);
return 69;
}
pir::nqp_native_call_setup__v();
my $nc_type := pir::get_knowhow__P().new_type(:name('NQPNativeCall'), :repr('NativeCall'));
$nc_type.HOW.compose($nc_type);
say("Created test type");
my $call := pir::nqp_native_call_build__PPsssPP($nc_type,
'foo.dll', 'GotValues', '',
nqp::list(
nqp::hash('type', 'int'),
nqp::hash('type', 'float')
),
nqp::hash('type', 'int'));
say("Created call...and now for invoking it...");
my $i := pir::nqp_native_call__PPPP(int, $call,
nqp::list(
nqp::box_i(42, int),
nqp::box_n(10.12, num)
));
say("And lived beyond call!");
say("Got back " ~ nqp::unbox_i($i));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment