Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Got it to work!</p> <p>Made the perl program, <strong>showtime.pl</strong>:</p> <pre><code>#/usr/bin/perl sub showtime { print "WOOT!\n"; } </code></pre> <p>Made the c program, <strong>perlembed.c</strong>:</p> <pre><code>#include &lt;EXTERN.h&gt; #include &lt;perl.h&gt; static PerlInterpreter *my_perl; void Initialize(char* processName, char* perlFile) { int argc = 2; char *argv[] = { processName, perlFile }, *env[] = { "" }; PERL_SYS_INIT3(&amp;argc, &amp;argv, &amp;env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, argc, argv, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; } void Call(char* subName) { char *args[] = { NULL }; call_argv(subName, G_DISCARD | G_NOARGS, args); } void Dispose() { if (my_perl != NULL) { perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); my_perl = NULL; } } </code></pre> <p>Compiled it via:</p> <pre><code>"gcc -shared -Wl,-soname,perlembed.so -o perlembed.so perlembed.c `perl -MExtUtils::Embed -e ccopts -e ldopts`" </code></pre> <p>Made this C# program, <strong>perlembed.cs</strong>:</p> <pre><code>using System; using System.Runtime.InteropServices; public class Woot { [DllImport("perlembed.so", SetLastError = true)] public static extern void Initialize(string processName, string perlFile); [DllImport("perlembed.so", SetLastError = true)] public static extern void Call(string subName); [DllImport("perlembed.so", SetLastError = true)] public static extern void Dispose(); static void Main() { Console.WriteLine("Starting up C#..."); try { Initialize("perlembed.exe", "showtime.pl"); Call("showtime"); } catch(Exception exc) { Console.WriteLine(exc.ToString()); } finally { Dispose(); } Console.WriteLine("DONE!..."); } } </code></pre> <p>Compiled it with gmcs, and got the output:</p> <pre><code>Starting up C#... WOOT! DONE!... </code></pre> <p>Hope this helps anyone out there, can't believe it took 3 languages to happen. I will move on to passing scalars, arrays, etc. but it should be a breeze from here.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload