One approach (based on universal.c):
#include <EXTERN.h> #include <perl.h> #include <XSUB.h> XS(XS_Package_sub_name) { ...[ Get arguments from Perl stack ]... rv = sub_name(arg); ...[ Return values on Perl stack ]... } int main() { static const char file[] = __FILE__; ... newXS("Package::sub_name, XS_Package_sub_name, file); ... }
The following are equivalent:
newXS("Package::sub_name, XS_Package_sub_name, file); newXSproto("Package::sub_name, XS_Package_sub_name, file, NULL); newXS_flags("Package::sub_name, XS_Package_sub_name, file, NULL, 0);
By taking this approach, you have to do everything XS would do for you manually. You will probably have a simpler time handling the arguments if you went the route of an XS module. If you do create an XS module, see "Using Perl modules, which themselves use C libraries, from your C program" in perlembed for how to load it up.
In reply to Re: Call a C function from Perl used from C
by ikegami
in thread Call a C function from Perl used from C
by nice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |