On Wed, Apr 28, 2021 at 5:38 PM Fernando Santagata <
nando.santag...@gmail.com> wrote:

> ,
> If you've found the Perl XS interface easy to work with, give Raku's
> NativeCall a try, you will find it amazing. Since you already know the C
> libraries, I guess you can cook an interface in no time.
>
>
Thanks for the pointer, Fernando.
I did take a look at "NativeCall".
The basics are pretty straightforward, and worked well enough on my Windows
7 box:

###########################
use NativeCall;
sub mpfr_get_default_prec() returns int32 is native('libmpfr-6') { * }
say "# ", mpfr_get_default_prec();

sub __gmpf_get_default_prec() returns int32 is native('libgmp-10') { * }
say "# ", __gmpf_get_default_prec();

# Correctly outputs:
# 53
# 64
###########################

The tricky bit is that nearly all of the gmp library functions want to take
either an mpz_t, mpq_t, mpn_t or mpf_t argument, but NativeCall knows
nothing about these types.
Similarly most of the mpfr library functions take an mpfr_t argument, which
is also a type that's unknown to NativeCall.

I guess it might be achievable via passing pointers and/or structs, both of
which are documented in the NativeCall docs.
However, I haven't knuckled down to working my way through it - and I'm not
even sure that it's do-able.

It would be much easier (and much more likely to happen ;-) if there was
some publicly available demo code to light the way to accessing the gmp (or
mpfr) library functions using raku's NativeCall capacity.

Cheers,
Rob

Reply via email to