Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to combine "embedded Perl" and XS to call from Perl to C?

2 views
Skip to first unread message

Manuel Reimer

unread,
Aug 21, 2014, 11:38:02 AM8/21/14
to per...@perl.org
Hello,

there are good examples on how to embed perl:

http://perldoc.perl.org/perlembed.html

And there are good examples on how to use XS:

http://perldoc.perl.org/perlxstut.html

My problem: The first tutorial only shows how to call from C to Perl and
the second one only shows how to call C functions and libraries.

What I'm searching for is some example that shows how I can allow my
embedded Perl interpreter to call functions in the C code that embeds
the interpreter.

My idea is to embed an interpreter into some application that only
allows plugins to be written in C. This application offers some header
files that have to be used by plugin developers. The resulting plugin is
a ".so" file which is loaded by the main application.

I guess embedding the interpreter will not really be a big deal and even
calling from "main application" into the loaded Perl script seems to be
pretty easy. The problem is that I somehow have to expose the API,
described by the header files, into my Perl script, to allow the Perl
code to call functions in the C API provided by the main application.

Maybe the second problem will be that the API is written in C++, but
maybe I'll just wrap this into a function oriented interface if it is
too difficult to expose a C++ class to Perl code.

Can someone give me some information on how to do this?

Thank you very much in advance.

Greetings,

Manuel
0 new messages