advancedscripthandling.htmlTEXTVIZF´Gµ(8Úµ(8Úí Advanced script handling

Advanced script handling

Making a script by script

Smile provides tools for dynamical editing of scripts - in other terms, for creating / editing a script ... by script. First of them, the coercions between script and text.
----------------------------
set script of window 1 to "-- aargh !"
----------------------------

You may also want to use the "script of" command, applied to a file reference.
----------------------------
script of theFile as text --> returns the script contained in theFile
----------------------------

Note the use of 'script of'. Use ' script of theFile' (instead of 'load script' and 'store script') to read scripts as text, and use 'LoadResource / PutResource' if you want to manipulate scripts. See Satimage osax for these commands.

Handling scripts as objects

Scripts behave most like objects, with the (virtual) following dictionary :

Class script :
Elements:
variable by numeric index, name
handler by numeric index, name
Properties:
container reference [r/o] -- the object containing the script
parent script [r/o] -- the parent script

The container property exists for the scripts attached to some Smile object.

Here are some examples.
----------------------------
name of handlers of class script of window 1
----------------------------
name of every variable of globals
----------------------------
handler "MaxInList" of class script of window 1 as text
----------------------------

Creating object classes - Making and using libraries

Smile lets you create dynamically (i.e., by script) classes, attach class scripts to them, which can have another such script as a parent, and so build hierarchical systems.
This system of custom class scripts in an implementation intended for defining and including easily custom libraries of scripts in objects of Smile.

Here are what it does, and the steps to follow.

1. Make the library script, as a class script.
For example, suppose you want a special class for Internet-aware text windows. You will first write a class script entitled, say, "Internet" which will provide Internet-oriented handlers to the text windows which include it (you will see below how a text windows 'includes' a library). The script could install some menus and / or buttons in the window when it is created (this is the 'prepare' handler's job). It could contain some all-purpose handlers that scripts related to Internet can call.
Save this script, preferably in the "Class Scripts" folder.

2. Make the new class.
The input needed to define a new class are, a 4-characters code ('class script' property), possibly a parent class ('parent' property), and the path to its class script ('path name' property) which was made above (just give the name of the file if it is located in the "Class Scripts" folder).
For instance the script below:
----------------------------
make new class script with properties {class script:"iTxt", parent:text window, path name:"Internet"}
----------------------------

will define the "iTxt" class as a child of the 'text window' class, and will set the "Internet" script file as its class script.
Once the class exists, you can open documents of this class, and they will inherit automatically the properties and handlers of the custom class script.

3. Create documents with the new class
To create a text window with the new class, run :
----------------------------
make new text window with properties {class script:"iTxt"}
----------------------------

To turn a standard text window ('theWind', say) into a window of the new class, run :
----------------------------
set class script of theWind to "iTxt"
----------------------------
Once saved, the document keeps its 'class script' property. Next time it will open as an "Internet-oriented" document.

4. Create a class when Smile launches
The script line:
----------------------------
make new text window with properties {class script:"iTxt"}
----------------------------

can work only if the "iTxt" class has been created before, as shown above (2.). This can be done on the fly, while Smile is running. To have it done automatically when Smile launches (so that you can double-clic a "iTxt" document even if Smile is not running yet), use the Initialization folder.

Custom sub-classes of custom classes

The mechanism described above allows for building a hierarchical system.
Suppose you want to derive a class of text windows from "iTxt" windows, specialized in HTML documents. The new class would declare "iTxt" as its parent (of course, it will hierarchically inherits the behaviors of the text window) :
----------------------------
make new class script with properties {class script:"html", parent:"iTxt", path name:"WebLib"}
----------------------------

èè_[ ReÊ Importing scripts/PluginsFCIMMMan]Ò"N"´¥u´¥x#!ğ!í#[ ReÊ Importing scripts/PluginsFCIMMMan]Ò"N"´¥u´¥x# ^«    İk¢  ©  İk¢+  G  İk¢¸  Õ  İk墌  s  ÔŸ  ¬  Ô°  Í  İk墄  ñ  İk¢õ  )  İk¢-  M  İk¢U  ±  İk¢µ  Õ  İk¢٠ %  İk¢)  I  İk¢Q  w  İk¢z  ‡  İk¢‹  -  Ô\  m  Ôq  ‰  İkÂ¢Ë  ê  İk¢ú  N  İk¢V  n  İk¢r    İk¢®  Ñ  İk¢  "  İk¢&  5  İk¢d  „  İk¢¯  Ó  İk¢    İk¢G  \  İk¢d  ´  İk¢¼  ×  İkÂ¢Û  û  İk¢ÿ  /  İk¢ 3  S  İk¢ W  |  İk¢ €     İk¢ ¤  é  İk¢ í   İk¢   Ô  İk¢ '  (  İk¢ ”  Ì  İk¢   N  Ô |   Ô ‘  ñ  İk¢ õ   İk¢ –  É  İk¢ Í  Î  İk¢ Õ    İk¢     İk¢  [  İk¢_  `  İk¢g    İk¢‰  ²  İk¢¶  Ø  İk墆  ü  İk¢  }  İk¢  ¡  İk¢©  -  İk¢1  Î  İk¢٠   İk¢  @  İk¢D  d  İk¢h  °  İk¢´  Ô  İk墆  5  İk¢9  Y  İk¢]    İk¢”  ´  İk¢¸  <  İk¢@  A  İk¢H  q  İk¢y    İk¢‘  ±  İk¢µ  ó  İk¢÷    İk¢  4  Ôw  ˆ  ÔŒ  —  İk¢  ,  İk¢f  ²  İk¢º  ¾  İk¢  â  İk墾  f  İk¢j  Š  İk¢²  ~selelist longÒlongÒpbndlist8longlongŒlong×long¸BDrwfalspvistrueWIDLfalsICFFlongrSiDlong€ptxfTEXTGenevaptpslong Rectlist8longlonglonglongWTBHlongRqULlongLWdtlongBrWdlongAuAdfalsTbSzlong èè_! Ø0ZstylSOUP&reco2€ÿÿ€ÿÿ b‚ f!í”cwtx