[comp.lang.perl] calling perl from C

george@cis.ohio-state.edu (George M. Jones) (04/26/91)

../usub/README in the 4.003 distribtuion says

> There is currently no official way to call a Perl routine back from C,
> but we're working on it.  It might be easiest to fake up a call to do_eval()
> or do_subr().  This is not for the faint of heart.  If you come up with
> such a glue routine, I'll be glad to add it into the distribution.

...so before I go spending a lot of time, and possibly fainting a few times,
I thought I would check with people here to see if anyone has already
come up with some way of calling perl routines from C.  I'd even welcome
pointers to unofficial mechanisims and/or pointers on how to "fake up a call"
(I've looked at do_eval and friends enough to know that I could realy stand
a few pointers as to what's going on with the internal stack handling, etc.)

Curious,
---George
-- 
OSU Computer & Inf. Science 2036 Neil Ave.,Columbus,Ohio 43210. 614-292-7325
george@cis.ohio-state.edu or ...!osu-cis!george
Dsylexai Strikse Agian.

usenet@carssdf.UUCP (John Watson) (04/26/91)

In article <1991Apr25.172948.655@cis.ohio-state.edu>, george@cis.ohio-state.edu (George M. Jones) writes:
> I thought I would check with people here to see if anyone has already
> come up with some way of calling perl routines from C.  I'd even welcome...

I have written a usersub.c for perl to access Faircom Ctree data base and Dtree
screen routines. With in the Dtree screens, they need to be able to handle
exceptions/hooks by calling perl routines or by executing perl expressions.
I do this by calling do_eval as follows.


	src = Str_new(99,40); /* make a place for the userfunc */
	str_set(src,parms);
	str = Str_new(99,0);
	interp(str,src,usub_sv_sp);
	str_free(src);
    rtn_cnt = do_eval(str,O_EVAL,curstash,G_SCALAR,usub_sv_sp);
    st = stack->ary_array + rtn_cnt;
	str_free(str);
	cp = (char *)str_get(stab_val(stabent("@",TRUE)));
 	if (*cp) {
		fatal ("Error in HOOK <%s>\n %s ",parms,cp);
	}


If you would like the whole source to wade through (1500 lines) just let me
know.

John Watson (self employed)