Re: Passing Perl pointers via PerlObjCBridge

2005-07-05 Thread Sherm Pendley

On Jul 5, 2005, at 12:56 AM, James Reynolds wrote:

I've tried passing perl pointers to Cocoa methods using the  
PerlObjCBridge.


Perl doesn't have pointers, Perl has references. They're  
superficially similar, but under the hood they're completely  
different beasts.



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


... Broken example snipped ...


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;
}


Here's a Perl version that works in both PerlObjCBridge and CamelBones:

#!/usr/bin/perl

use strict;
use warnings;

use Foundation;

# Or, use CamelBones instead... :-)
# use CamelBones qw(:Foundation);

# Allocate enough space to hold a 4-byte int
my $value = \0 x 4;

# Create a scanner
my $scanner = NSScanner-scannerWithString_('12358D');

# Get a pointer to $value, with pack(). That pointer is returned
# in a 4-byte string scalar, *not* as a numeric value - to  
promote

# those 4 bytes to a numeric value, we unpack() them:
my $valuePointer = unpack(L, pack(p, $value));

# Scan
$scanner-scanHexInt_($valuePointer);

# Now, use unpack() to interpret the four bytes that were stored in
# $value as an integer
my ($intValue) = unpack(I, $value);

print Int value: $intValue\n;

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org



Re: How to build 5.4.5 on OS X

2005-07-05 Thread Michael G Schwern
On Mon, Jul 04, 2005 at 07:28:55PM -0500, Ken Williams wrote:
 With a hint from Jarkko I got 5.4.5 to build on OS X.  Here's how.
 
 Do I hear a 5.4.6 in the future, then? ;-)

Because we want to simultaneously maintain 1..2..3..4..5 tracks of Perl.
5.4.x, 5.5.x, 5.6.x, 5.8.x, 5.9.x.  (8 if you include Pugs, PONIE and Perl 6).


-- 
Michael G Schwern [EMAIL PROTECTED] http://www.pobox.com/~schwern
'All anyone gets in a mirror is themselves,' she said. 'But what you
gets in a good gumbo is everything.'
-- Witches Abroad by Terry Prachett