Ok, this is a very interesting question and there may not be any easy way to do this but figured I would throw this out there before deciding that modifying Perl is my underlying answer.
So I've got a C application that calls Perl scripts in an embedded fashion. This all works fine and dandy and it's pretty awesome that I can pass information in and get information back out. HOWEVER, now onto my next conquest; I need to allow my embedded script(s) to be able to call some functions within the C application that ORIGINALLY CALLED IT.
This is important because XSUB would require it to be an external library; but I don't want it to be an external library I want it to be a direct call to the C function(s). Now maybe this can be done via XSUB and I've just been reading and understanding it wrong.
Application -(run)-> Perl
Application <-(function_x())- Perl
Application -(returnfunction_x)-> Perl
The reason this cannot be an external library is because I am relying on data that is solely created/stored within the application.
XSUBs actually don't require there to be an external library. They merely provide the ability to call to a c function from perl space, and provide some convenience in mapping the calling conventions between C and Perl.
All you need to do is register XSUBs you compiled into the embedding application with the perl interpreter you're embedding.
When embedding perl, this sort of thing is usually done in the xs_init function you pass to
parse_perl
.After that you'll be able to call to the XSUB as
Some::Perl::function
from perl space, and that XSUB in turn is free to call back to your application in any way it wants to.