I've tried passing perl pointers to Cocoa methods using the PerlObjCBridge. I can't get it to work, probably because Perl pointers "don't let you peek and poke at raw memory locations" (Adv Perl Programming). Does anyone know of a way to get this to work?

For example, I'm trying to pass an int by reference:

#!/usr/bin/perl

use Foundation;

my $value;
$rawdata = NSString->stringWithFormat_("12358D");
$scanner = NSScanner->scannerWithString_( $rawdata );
$scanner->scanHexInt_( \$value );
print $value;

Nothing prints.  Here is the Cocoa code, which works.


#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int val;
    NSString        *rawdata = [NSString stringWithFormat:@"12358D"];
    NSScanner        *scanner = [NSScanner scannerWithString:rawdata];
    [scanner scanHexInt:&val];
    NSLog (@"%d", val);

    [pool release];
    return 0;
}

Another example is this, which tries to pass a pointer to raw bytes. However, I may not have a full understanding of this code, as I don't really work with raw data much (pack, and dataWithBytes expects a "const void *"). (I've tried many different forms of the following code, and I haven't gotten anything to work correctly).


#!/usr/bin/perl

use Foundation;

$bytes = pack ("H*", "12358D" );
$data = NSData->dataWithBytes_length_( \$bytes, length $bytes );
print $data->description->cString();


--

James Reynolds
http://james.magnusviri.com
[EMAIL PROTECTED] - [EMAIL PROTECTED]

Reply via email to