Reputation: 176
In perl5 it was easy to link in libperl.so, set some variables and run some code, with callbacks. Is there a story for doing this in perl6?
Upvotes: 13
Views: 688
Reputation: 23527
Besides what @elizabeth-mattijsen has commented, no, there's no such thing. While the perl interpreter was a monolithic thing which might be relatively easily turned into a .so
library and then linked with some API endpoints, Perl 6 is two big things: a virtual machine, either Java or MoarVM, plus the interpreter, Rakudo. There could be an scenario in which you wouldn't need to embed Java or MoarVM, because both languages would be running in the same VM. Think Perl 6 embedded in Clojure, for instance. Or Perl6 embedded in 007, both running in MoarVM. That would be kind of easy, and you would be targeting a VM with the same capabilities. But C++, C and Perl6 have a very different abstract virtual machine as a target; think about the Unicode handling, or the concurrent interface. Embedding Perl6 in C would be basically running Perl6 programs from C, instead of running them from the command line.
It is possible that, in the same way Perl regexes ended all over the place, some Perl 6 capabilities, like Unicode handling or grammars, could end up ported or embedded in other languages. But I don't see a clear use case for embedding Perl in C or C++, right now, and devoting some effort for that kind of thing would be, thus, better employed in something completely different.
Upvotes: 4
Reputation: 465
This isn't an answer, but suppose I've got an already existing C program which is designed to use plugins which are .dlls or .sos, and they get loaded via dlopen or LoadLibrary, an API entry point is found using dlsym or GetProcAddress, then that entry point is called with some sort of handle for the plugin to make calls back into the main process.
Now, suppose I want my plugin (inside of this .dll or .so) to load moarvm, and then run some perl6 script, which in turn uses NativeCall to call back into the main process. How would I go about doing this?
Alternatively, suppose I want my plugin (inside of this .dll or .so) to load the jvm, then run some perl6 script, etc. How would I go about doing this?
Loading perl5 just to load perl6 seems like a silly solution. It might work, but...
Upvotes: 2
Reputation: 26924
I think you can find the state of the art in that respect at https://metacpan.org/pod/Inline::Perl6 , which embeds Rakudo in Perl 5.
Upvotes: 7