TIP: Click on subject to list as thread! ANSI
echo: st_prog
to: Rodney Rudd
from: Evan Langlois of 1:124/7028.0
date: 1996-01-09 22:47:54
subject: Re: PERL?

EL>  write modules in C and dynamically load them into PERL (dynamic
 RR>  
 RR> Can you give me a brief example of what this would look like inside a C
 RR> source file?

 Only if JGT promises to be good and leave us alone :-)

 I actually don't have any good examples - I'd have to look them up.
 Basically, you can't put the code directly into C, instead PERL
 has some C functions you can link into your C code that allow you
 to call Perl functions, and subroutines written in PERL.  There
 is also an interface to go the opposite direction as well.  I
 haven't really made use of either one of these yet though.

 Here is an example - this is actually part of the 'miniperl' C code.
 It contains the code to start up the interpretter and do its thing,
 everything else is just more PERL stuff you can link in.  So, you
 wind up adding most (or maybe even all) of PERL into your C code,
 but you can control it, and even call PERL subs from C.

#include "EXTERN.h"
#include "perl.h"
static void xs_init _((void));
static PerlInterpreter *my_perl;
int main(argc, argv, env)
int argc;char **argv;char **env;
{
    int exitstatus;
    if (!do_undump) {
        my_perl = perl_alloc();
        if (!my_perl)
            exit(1);
        perl_construct( my_perl );    }
    exitstatus = perl_parse( my_perl, xs_init, argc, argv, env );
    if (exitstatus)
        exit( exitstatus );
    exitstatus = perl_run( my_perl );

    perl_destruct( my_perl );
    perl_free( my_perl );
    exit( exitstatus );
}


There is also the XSUB interface, as mentioned above, for calling PERL
subroutines :

via this XSUB
    void    Call_fred()
        CODE:
        PUSHMARK(sp) ;                perl_call_pv("fred",
G_DISCARD|G_NOARGS) ;
        fprintf(stderr, "back in Call_fred\n") ;


I wish I knew how the above works, as you can see, it defined some
C stuff, but yet, it isn't C (note the lack of braces!).  There are
some PERL extensions written using  this.  I guess that PERL parses
it and writes the actual code.


--- Maximus/2 3.01

[+/188 of 200/107 Mins] = * FIDO: ST_PROG =: Next...
* Origin: Wylie Connection 33.6K USR V34+ DS 214-442-0388 (1:124/7028)

SOURCE: sfhq

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.