|Syntactic Confectionery Delight|
Re^3: Accessing an XS function from a Perl function of the same nameby syphilis (Chancellor)
|on Mar 04, 2017 at 05:54 UTC||Need Help??|
If you want to wrap a library function (let's call it 'foo') in an XS sub, and be able to call that XS sub from perl as 'foo', then you make use of the XS PREFIX option - which allows you to specify a prefix that will be automatically stripped from the XS sub when it is bound to perl.
For example, specify PREFIX as 'wrap_this_', write the XS Sub as:
Then, when you call foo(16) in perl, wrap_this_foo(16) is executed.
Here's an Inline::C demo that gets a perl function named 'foo' to execute a C function named 'foo', via an XS sub named 'wrap_this_foo' that wraps the C sub 'foo'.
If you comment out the the wrap_this_foo XS sub and re-run the script then you get:
I hope that proves that the original run was, in fact, calling wrap_this_foo and not directly calling the C function foo (which is invisible to perl).
Update: It's invisible to perl because perl's typemap doesn't explain how to deal with the type 'unbind'.