Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending an Objective-C program with a scripting language

Is there a ready-made implementation of an interpreter for ObjC. Basically, I need my program to be extendable via a scripting language.

I'm not sure if this is already provided by some kind of framework, or perhaps I can implement AppleScript internally - not sure how I would do that tho. It seems to only apply to automating the program itself, not for extending its own functionality.

Something similar to mIRC's means of interfacing with a scripting language.

like image 508
AWF4vk Avatar asked May 27 '11 17:05

AWF4vk


3 Answers

You bet there is. It's called FScript; it's open-source and includes a console with a REPL in which you can interact with Cocoa objects. The syntax is Smalltalk-like, which is very similar to Objective-C -- the main difference is no square brackets. Here's some snippets from their tutorial. Notice that variables don't have to be explicitly typed!

> imageLocation := NSURL fileURLWithPath:'/Library/Desktop Pictures/Nature/Clown Fish.jpg'.

> image := CIImage imageWithContentsOfURL:imageLocation.

> image drawInRect:(200<>80 extent:600<>400) fromRect:image extent operation:NSCompositeSourceOver fraction:1.

You will be interested in their Embedding FScript Into Cocoa Applications Guide.

like image 190
jscs Avatar answered Nov 15 '22 02:11

jscs


Do you just want your program to be scriptable? If so, then you should probably add AppleScript support. See Introduction to Cocoa Scripting Guide for information on how to do this.

like image 43
Andy Avatar answered Nov 15 '22 02:11

Andy


Python and Ruby can interact with the Objective C calls so you can use them to extend the program's functionality.

like image 42
mmmmmm Avatar answered Nov 15 '22 02:11

mmmmmm