![]() | objective.st | ||||||||||
| ScriptingObjective-S has been carefully designed to remove barriers between scripts and programs, to the point of making the differences disappear. Scripts have direct access to the full power of the system frameworks, and methods written in Objective-S have all the power of a scripting language. In-App ScriptingMost of Objective-S comes as a framework, and can therefore be added to an application by linking in the framework.
It is also easy to add methods to classes, and there is a MethodServer that enables loading classes into a running process via HTTP. As one example, the BookLightning imposition program uses embedded Objective-S scripts to control the actual imposition process.
` Unix ScriptingObjective-S comes with a Unix REPL called
The method declaration in the second line acts as an architectural adapter,
giving
Scripts have full access to Cocoa classes. The following script uniques the
arguments passed on the command line via an
The
Although the Web-ScriptingObjective-S makes it easy to interact with web resources. The following example looks up a zip-code using the zipTastic web service.
Web serving is supported using the Objective-HTTP micro framework. A trivial Hello World server looks as follows:
After we load the ObjectiveHTTPD framework, we create a scheme handler that operates
in memory and hook it up to the URI scheme As another example, you can serve a specific directory by substituting the in-memory scheme with a directory reference (that''s converted to a scheme handler implicitly):
framewok:ObjectiveHTTPD load. (dir -> (MPWSchemeHttpServer serverOnPort:8081)) startHttpd. Scheme handlers can manage access to objects, respond dynamically by computing values or combine other scheme handlers. Apple-ScriptingThrough use of the scripting bridge, it also becomes easy to control other applications via Apple Events, for example setting the iChat status message to the current iTunes track name.
This can be used directly from Unix scripts or application code without having to deal with script strings and try to pass arguments to those scripts via string processing or other means. If I want to prefix the current track name, I just write the code to do it:
(Note that the ScriptinBridge framework and corresponding schema are not loaded
into the scripting environment by default, you need to add them by executing
| ||||||||||
Copyright (c) 2012-2020 Marcel Weiher (st) |