#include "cep.h"
[..]
CEP_InitPerl( xs_init );
[..]
(void)CEP_DestroyPerl( );
% perl -MExtUtils::Embed -e xsinit -- -o xsinit.c -std IO::SocketYou must link this file to your program, and specify xs_init in to CEP_InitPerl. Otherwise, if you do not need XS based perl module, you can pass NULL as xs_init.
ret = CEP_PerlEvalVa( "print \"Hello Interpreter!\n\"", NULL);prints the "Hello Interpreter!" message. The first argument contains the perl code. The last parameter is always NULL, this indicates the end of the command.
int a;
char * b;
double c;
ret = CEP_PerlEvalVa("$a = 1; $b = \"SUCCESS\"; $c = 3.141592 ; "
"return $a, $b, $c;",
CEP_INT, &a,
CEP_STR, &b,
CEP_DBL, &c,
NULL);
ret = CEP_EvalFileVa( "tests/file_eval_test", NULL);
int a_in, a_out;
double c_in, c_out;
char b_in[128], *b_out;
[..]
CEP_PerlEvalVa("sub main::test_function {"
"my ($a,$b,$c) = @_;"
"return $a,$b,$c;"
"}",
NULL);
[..]The return value is negative if an error is occoured, otherwise it returns with the number of the return variables. The function allocates space for \0 terminated CEP_STRs.
CEP_PerlCallVa("test_function",
CEP_INT, a_in,
CEP_STR, b_in,
CEP_DBL, c_in,
CEP_OUT,
CEP_INT, &a_out,
CEP_STR, &b_out,
CEP_DBL, &c_out,
NULL);
int CEP_SetInt ( IN char * variable, IN int value ); |
Set integer variable to value. |
int CEP_GetInt ( IN char * variable, OUT int * value ); |
Get variable's value and store it as integer to value. |
int CEP_SetDouble ( IN char * variable, IN double value ); |
Set double variable to value. |
int CEP_GetDouble ( IN char * variable, OUT double * value ); |
Get variable's value and store it as double to value. |
int CEP_SetString( IN char * variable, IN char * value ); |
Copy '\0' terminated character array to variable
as string. After SetString the value can be reused. |
int CEP_SetStringN( IN char * variable, IN char * value, IN size_t len); |
Copy len bytes from value to variable. Value
can contains '\0' s. |
int CEP_GetString ( IN char * variable, OUT char ** value, OUT size_t * len ); |
Copy variable to value and set len to string's length.
The necessary memory is allocated by GetString. Value can contain '\0'.
|
int CEP_CatStrings( IN char * variable, IN char * value); |
Append value to variable. |
int CEP_CatStringsN( IN char * variable, IN char * value, IN size_t len); |
Append len bytes from value to variable. |
int CEP_CatStringVariables( IN char * variable1, IN char * variable2); |
Concat two perl variables. |
Examples:
CEP_SetInt("main::a", 2);
CEP_SetString("main::b", "success");
CEP_SetDouble("main::c", 1.414213f );
CEP_GetInt("main::a", &a);
CEP_GetString("main::b", &b, &len);
CEP_GetDouble("main::c", &c);
CEP_CatStrings("main::b", a2_in );
CEP_CatStringsN("main::b", a3_in, 4 );
CEP_CatStringVariables("main::b", "main::d" );
Hosted by Sourceforge. |
|
$Id: C_Embedded_Perl.html,v 1.1 2002/12/20 10:04:03 crow Exp $