When you mostly want to call C code from perl it's easiest to build a perl module with XS code and use that module like you would any other perl module. XS code is basically C code with a whole lot of macros and extra syntax to make it easy to talk to the perl interpreter and to make it easy to "export" C functions to perl (so they can be called like any other perl function).
See perlxstut for starters. Because XS code is mostly C, you would have to include any header files you'd normally need to include in a C program plus the header files that XS/perl needs. You would also have to make sure your code is linked to any libraries/objects you need just like regular C (though perl's ExtUtils::MakeMaker can make it reasonably easy to do so portably).
If your setup really works the other way around (i.e. you're mostly calling into perl from C) you can embed a perl interpreter in your C code and just call perl functions whenever you need them. Apart from how you compile/link your program there isn't really much difference between the two options as far as communicating between the perl and C side of the program is concerned.
See also, perlapi, perlembed, perlcall, perlxs and the Manning book "Extending and Embedding perl".
|