BrowserUk wrote:
Could domeone please show me how to code the equivalent of the following sub 
but using the Inline_Stack_* macros instead of the XS varients?

int callComp( SV* cmp, SV* a, SV* b ) {
        dSP;
        int rv;
        
        PUSHMARK(SP);
        XPUSHs( newSViv( SvIVX( a ) ) );
        XPUSHs( newSViv( SvIVX( b ) ) );
        PUTBACK;

        if( call_sv( cmp, G_SCALAR ) != 1 )
                croak( "Bad comparator" );
        SPAGAIN;

        rv = POPi;

        PUTBACK;
        return rv;
}


I think you'll find that works, as is, in an Inline C script.

Is there any particular reason that you want to incorporate the Inline Stack macros into it ? There's an example of a callback in the Inline::C-Cookbook - but it produces really weird results if you call it a number of times in a loop. On the rare occasions that I've wanted a callback I've completely ignored the stack macros and instead taken the advice of 'perldoc perlcall'. My advice would be to do likewise :-)

My assumption (not necessarily correct) is that the stack macros are inadequate when it comes to callbacks. You'll find them defined in Inline::C.pm. (Note that there's no mention of 'dSP', 'PUSHMARK', 'SPAGAIN', and 'POPi'.) You could probably use those C.pm stack macro definitions to work out how to incorporate them into the script if you really want to.

In the above script 'PUTBACK' (the equivalent of Inline_Stack_Done) is called twice. That doesn't make much sense in terms of what the Inline documentation tells us about 'Inline_Stack_Done'.

Cheers,
Rob



Reply via email to