jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I had a look at perlembed, and I thought that It'd be quite useful to access to same feature in Perl.

Is there any XS binding to the PerlInterpreter API?

Cheers!

Replies are listed 'Best First'.
Re: Embed Perl in Perl
by BrowserUk (Patriarch) on Mar 15, 2011 at 18:27 UTC
    Is there any XS binding to the PerlInterpreter API?

    Better yet, there's a core module for doing that?

    use threads; ## Run code in a seperate interpreter async { ...; };

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Perlembed documentation does have a bullet called "Use Perl from Perl" in the preamble listing do, eval, require and use. Should we suggest to the perldoc owners (I don't know how this is maintained) that they add threads' async function to the list?


      #my sig used to say 'I humbly seek wisdom. '. Now it says:
      use strict;
      use warnings;
      I humbly seek wisdom.

        You could try sending p5p a doc patch to that effect, but I wouldn't hazard a guess as to their acceptance.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Embed Perl in Perl
by ikegami (Patriarch) on Mar 15, 2011 at 17:54 UTC

    The code in XS files is C code, so if you want to create a Perl interpreter from a Perl interpreter, go right on ahead and do it.

    Or are you really asking if you can use the Perl API from XS code? Most definitely yes.

Re: Embed Perl in Perl
by ambrus (Abbot) on Mar 15, 2011 at 20:21 UTC

    There's a proof of concept module that does this. It's called Perl.

      Definitely what I need, but it seems this have stopped compiling for a while.

      Sounds that I will have to go through perlapi :)

Re: Embed Perl in Perl
by Anonymous Monk on Mar 15, 2011 at 17:55 UTC
    Embedding Perl in Perl? Sounds like a job for eval...

      My problem is that eval operates in the same memory space as the current Perl interpreter instance.

      Maybe there's a way around this? It doesn't sound sane to me though.

        We have to go deeper . . .</ObInception>

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Re: Embed Perl in Perl
by Anonymous Monk on Mar 15, 2011 at 22:48 UTC

      Does what I need in theory, but doesn't work with Perl > 5.8 :(

      I gave a go at Safe, but I couldn't manage to make it load dynamic modules.