my $str = NSString->stringWithString_("astring");
does work with PerlObjCBridge. In general, if an Objective-C method
expects an object and you pass a Perl string, PerlObjCBridge
autoconverts the Perl string to an NSString.
NSString return values are not autoconverted to Perl strings, by
design. There are valid arguments either way. It is easy, of
course, to get the Perl string by appending "->cString()" to the
method invocation or return value.
PerlObjCBridge does not do the other kinds of autoconversion that
CamelBones does. It does provide functions to convert back and forth
between plists and Perl structures. See Foundation.pm or the
PerlObjCBridge man page.
- Doug
On Dec 28, 2005, at 6:09 PM, Manfred Bergmann wrote:
Thx. That works like a charm.
The toll-free bridge also includes something like this?
my $str = NSString->stringWithString("astring");
where with PerlObjCBridge you have to use this:
my $str = NSString->stringWithCString_("astring");
Best regards,
Manfred
Am 29.12.2005 um 12:34 schrieb Sherm Pendley:
On Dec 28, 2005, at 7:05 PM, Manfred Bergmann wrote:
I want to use some Foundation objects like NSDictionary and
others in a Perl script (because of writing a plist of that).
I succeeded with using PerlObjCBridge (use Foundation).
Is this possible with CamelBones, too? Sherm?
Yes, it is. When you install CamelBones, it installs a "embedded"
framework and Perl module in /Developer/CamelBones; that's the one
that gets copied into .app bundles for GUI apps. It also installs
a "shared" framework in /Library/Frameworks, and a Perl module
that uses that framework under /Library/Perl, so you can use those
from standalone .pl scripts.
Because a .pl file isn't a bundle, you can't package it up with an
embedded copy of the framework. If other people want to use your
script, they'll need to install the CamelBones package.
CamelBones and PerlObjCBridge are very similar, but there are some
differences.
CamelBones supports subclassing of Cocoa classes.
Cocoa exceptions in CamelBones are caught with an eval {} block.
PerlObjCBridge handles exceptions with a callback function.
CamelBones has support for toll-free bridging. If you call a
method in scalar context that returns an NSDictionary or NSArray,
you get an object returned. But, if you call it in list context,
you get a tied hash or array instead. So you can use "for (keys %
foo)" instead of NSEnumerator to access the elements of an
NSDictionary, for instance.
The toll-free bridging works the other way too - you can pass an
array or hash ref wherever an NSArray or NSDictionary is expected.
NSPoint, NSRange, NSRect, and NSSize structs can also be passed as
array or hash refs.
With CamelBones, the trailing underscore when you call Cocoa
methods that take one or more arguments is optional. So you could
write either $object->doFoo_($bar) or $object->doFoo($bar).
PerlObjCBridge requires the trailing underscore.
Of course, there's this:
use CamelBones qw(:All); # Or qw(:Foundation) if you don't
want AppKit imports
vs. this:
use PerlObjCBridge;
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org