I'm trying to write a C function that will return a scalar value. In
between, the C function will call back to a Perl function to help it
along. I have read that I shouldn't use Inline_Stack_Vars when calling
back to Perl so I'm using the examples in perldoc percall instead. Here's
a skeleton example of what I'm trying to do:

use Inline C;

sub exclaim {
    my $string = shift;
    return "$string!";
}

call_exclaim("Hello");

__END__
__C__

void call_exclaim(SV* string) {
    dSP;
    int count;

    ENTER;
    SAVETMPS;

    PUSHMARK(SP);
    XPUSHs(sv_2mortal(newSVsv(string)));
    PUTBACK;

    count = call_pv("exclaim", 0);

    SPAGAIN;

    if (count != 1) {
        croak("Big trouble\n");
    }

    PUTBACK ;
    FREETMPS ;
    LEAVE ;

    // Return value on stack?
}

The exclaim subroutine just appends a "!" to a scalar. I figure when
call_pv("exclaim", 0) is called, the return value of exclaim is now on the
stack. How do I get this scalar to be returned to Perl (since I can't use
Inline_Stack_Return(n) since Inline_Stack_Vars isn't being used)?

--Tao

Reply via email to