On 4 Nov 2012, at 1:03 AM, John Delacour wrote:
> Perl is another matter altogether.  While I am getting up to speed with Obj-C 
> I would like to be able to include Perl routines within projects, and I can 
> find very little on the WWW to be guided by.  So far I have experimented 
> simply with
> 
>  system ("hard-coded/path/to/file")

This works, but it blocks the entire app while the script runs, and is 
suboptimal in some other ways. It's fine for quick&dirty use but I'd recommend 
using something like NSTask for a program you're going to ship to other people.

> I have not yet even attempted anything with NSTask and found no way to add 
> Perl scripts to the project file tree and refer to them by relative path, so 
> you can see I am not very far forward!

Perl scripts would just be ordinary resources as far as Xcode is concerned; 
you'd add them to the "copy bundle resources" build phase. Xcode will copy them 
into your .app when you build. You can then find the path to a given bundle 
resource at run time using NSBundle methods like -pathForResource:ofType:. (The 
application itself is a bundle, which can be gotten using [NSBundle 
mainBundle]; frameworks, plugins, and the like are also bundles.) The path is 
an NSString; if you're giving it to NSTask, you can pass it as-is. If you want 
to give the path to a POSIX API (like system() or exec()), you can convert it 
to an appropriate C-style string using the -fileSystemRepresentation method.  
(In practice the file system representation is just UTF-8, but it's probably 
best to use -fileSystemRepresentation instead of hardcoding that bit of 
knowledge.)

Hopefully this helps you connect the dots--- all the methods I've mentioned 
should have more detailed info in the documentation.


It's also possible to link libperl.dylib directly into your app and use it as 
an embedded interpreter. I haven't tried this, though, so I don't know what 
problems you might hit.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to