Io programming with Piranhas
This document is a small introduction to using Io as a scripting language for Piranhas. By default, Piranhas applications should be written in Io, though you can if you want, use Piranhas as an Objective-C library and use either Objective-C or Io, or both.
Piranhas primitives in Io
The Io interpreter embedded in Piranhas comes with a set of new keywords, that allow to easily interface with Piranhas kernel:
kernelis a reference to the actively running Piranhas kernelExecutionis a reference to the current execution serviceSIPis a reference to the current SIP serviceBehavingis a reference to the current beahving serviceactionis a primitive that can be used as theblockprimitive is used, excepted that it will create a Io block wrapped into a Piranhas executable. The action is not executed until you give it to eithercallordelay(see below).action1is equivalent toactionexecpt that the action will take an argument when executed.calldirectly submits an action to the Piranhas execution engine. This operation is asynchronous, which means that it won't return any value and won't execute directly.delayis the same as call, but takes a decimal value expressing the delay (in seconds) before the action gets executed
Apart from these specific primitives and objects, any Objective-C class and instance is directly accessible in Io.
For instance, you could call the [PKernel? kernel] method in Io by doing PKernel? kernel.
Io and Objective-C
Io is really well integrated with Objective-C, however there are a number of things that should be taken care of:
- Objective-C objects created directly from Io code (either from
allocor by class-level factory methods) are all retained. This means that newly allocated objects must be release to avoid memory leaks.
