Creating and returning a code-reference from a XS routine

W

wikenfalk

Hi

I want to create a SV * which references CODE.

In c I would do

void *fptr {
int afunc(void);
return (void *) &afunc;
}

Now I would like to

SV *
fptr

CODE:
RETVAL = newRV_noinc( (SV *) &XS_fptr);

OUTPUT:
RETVAL

(ignore that the name of the function is probably not correct .. that
part I have sorted out.)
The problem is how to generate the correct RETVAL.
I cannot find this information in perlguts .. maybe because I don't
understand ..

/xb
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to

Now I would like to

SV *
fptr

CODE:
RETVAL = newRV_noinc( (SV *) &XS_fptr);

OUTPUT:
RETVAL

What is XS_fptr? A C function which is an XS?

Then look into the .c file generated from your .xs file. In the BOOT
section, there is some autogenerated code to register XS functions.
Just copy and paste it yourselves...

Hope this helps,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top