summaryrefslogtreecommitdiffstats
path: root/funtools/tperl.c
diff options
context:
space:
mode:
authorWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 17:38:41 (GMT)
committerWilliam Joye <wjoye@cfa.harvard.edu>2016-10-27 17:38:41 (GMT)
commit5b44fb0d6530c4ff66a446afb69933aa8ffd014f (patch)
treee059f66d1f612e21fe9d83f9620c8715530353ec /funtools/tperl.c
parentda2e3d212171bbe64c1af39114fd067308656990 (diff)
parent23c7930d27fe11c4655e1291a07a821dbbaba78d (diff)
downloadblt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.zip
blt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.tar.gz
blt-5b44fb0d6530c4ff66a446afb69933aa8ffd014f.tar.bz2
Merge commit '23c7930d27fe11c4655e1291a07a821dbbaba78d' as 'funtools'
Diffstat (limited to 'funtools/tperl.c')
-rw-r--r--funtools/tperl.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/funtools/tperl.c b/funtools/tperl.c
new file mode 100644
index 0000000..485fafe
--- /dev/null
+++ b/funtools/tperl.c
@@ -0,0 +1,39 @@
+/*
+ http://search.cpan.org/~nwclark/perl-5.8.7/pod/perlembed.pod
+ gcc -o tperl tperl.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
+ */
+
+#include <EXTERN.h> /* from the Perl distribution */
+#include <perl.h> /* from the Perl distribution */
+
+static PerlInterpreter *my_perl; /*** The Perl interpreter ***/
+
+int main(int argc, char **argv, char **env)
+{
+ STRLEN n_a;
+ char *embedding[] = { "", "-e", "0" };
+
+ PERL_SYS_INIT3(&argc,&argv,&env);
+ my_perl = perl_alloc();
+ perl_construct( my_perl );
+
+ perl_parse(my_perl, NULL, 3, embedding, NULL);
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+ perl_run(my_perl);
+
+ /** Treat $a as an integer **/
+ eval_pv("$a = 3; $a **= 2", TRUE);
+ printf("a = %d\n", SvIV(get_sv("a", FALSE)));
+
+ /** Treat $a as a float **/
+ eval_pv("$a = 3.14; $a **= 2", TRUE);
+ printf("a = %f\n", SvNV(get_sv("a", FALSE)));
+
+ /** Treat $a as a string **/
+ eval_pv("$a = 'rekcaH lreP rehtonA tsuJ'; $a = reverse($a);", TRUE);
+ printf("a = %s\n", SvPV(get_sv("a", FALSE), n_a));
+
+ perl_destruct(my_perl);
+ perl_free(my_perl);
+ PERL_SYS_TERM();
+}