[Israel.pm] Embedding perl in a C++ program

Gaal Yahas gaal at forum2.org
Thu Dec 30 11:28:38 PST 2004

David Rachamim wrote:

> As I understand, Inline::CPP helps calling C++ functions from Perl. My
> problem is that even if I can do this I still have to implement some
> mechanism to communicate between the code that is running in the Perl
> interpreter (even the C++ code) and the code in the main application --
> What I need is a convenient way to let the Perl script be aware of the
> context of the application within which it is running.
> Am I missing something? -- If you meant I can use Inline::CPP in some
> different way, please elaborate

You can call C++ functions from perl with whatever data you like,
such as the results of a script's run, or, if the script plays
nice, its runtime progress. You can also call in an init routine
from C++ to perl that sets up some globals, things the script may
want to know, maybe load some Perl modules automatically: set up
the scripting environment.

For example, if you agree to replace calls to print with my_print(),
my_print() can be a C++ funtion in your main app that adds a message
to the script console.

An embedded perl interpreter has its own Perl context, but it runs
*right in* your main app. If it is single threaded, you need to
yield control over to the GUI event loop from time to time. But this
is no different from having a C++ submodule in your code.

Inline effectively makes the language difference transparent. How
would you implement *any* scripting host? You have to design that
first, then do it with Perl.


Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list