narse has asked for the wisdom of the Perl Monks concerning the following question:
This example prints "OK". The easy solution for this example is to manually set scalar = NULL but I cannot do this. My hope is to handle perl hash arguments by stuffing them into a map:void test() PREINIT: SV *scalar; CODE: if ( scalar == NULL ) // fixed std::cout << "NULL\n" if ( SvOK( scalar ) ) // fixed std::cout << "OK\n"
In this example, if the foo argument was never given, the map will return the default value for a SV * which will point to nothing.void test( ... ) PREINIT: std::map< std::string, SV *> args; INIT: for ( int i = 1; i < items; i += 2 ) args[ SvP_nolen( ST(i) ) ] = ST( i + 1 ); CODE: std::cout << "The value of `foo' is " << SvP_nolen( args["foo"] ) << "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS/Guts and unset scalar pointers
by ysth (Canon) on Apr 04, 2005 at 14:36 UTC | |
by narse (Pilgrim) on Apr 04, 2005 at 14:43 UTC | |
|
Re: XS/Guts and unset scalar pointers
by narse (Pilgrim) on Apr 04, 2005 at 15:32 UTC |