bgiii has asked for the wisdom of the Perl Monks concerning the following question:

I have an embedded Perl app where I generate a hash reference in perl and pass this back to C. If I print the hex address in both Perl and C, I get the same number.

I don't intend to use the pointer in C, just pass it around as an opaque pointer.

My question is how to get this void * from C back into Perl so that I can access the contents of this hash reference. Now I can push simple stuff onto the stack, but what I need to be able to do is push this hash reference address on the stack such that when I call this Perl code via call_pv, I can access this perl function (for instance):

sub foo {
  my ($href, $key) = @_;
  print $href->{$key};
}
Thanks a bunch. This is a hard one to google for... WGIII

Replies are listed 'Best First'.
Re: hash ref to & from C
by dave_the_m (Monsignor) on Sep 10, 2005 at 13:06 UTC
    something like:
    void call_foo(HV* hash, SV* key) { dSP; PUSHMARK(SP); XPUSHs(hash); XPUSHs(key); PUTBACK; (void) call_pv("foo", G_VOID); SPAGAIN ; }
    See perlcall for more details

    Dave.

Re: hash ref to & from C
by samtregar (Abbot) on Sep 10, 2005 at 20:00 UTC
    The Perl man-pages are good but I recommend you pick up a copy of Extending and Embedding Perl. It is far and away the best reference for the C side of Perl programming.

    -sam