Saving scripts

12 views
Skip to first unread message

GMan3rd

unread,
Oct 31, 2009, 12:52:23 AM10/31/09
to F-Script
I know this is going to sound odd. But I have yet to find a way to
save scripts. How do I save scripts? Other than writing in XCode that
is.

Philippe Mougin

unread,
Oct 31, 2009, 2:06:48 PM10/31/09
to F-Script
I usually write my scripts using an external text editor and save them
as text files. I express them in the form of blocks literals (i.e.,
code between brackets) so I can easily load them programmatically
from F-Script, if needed, using NSString methods such as
"stringWithContentsOfFile:encoding:error:" combined with FSSystem's
"blockFromString:" method.
To programmatically save a block from F-Script to a text file you just
have to get its source code in an NSString, using the "description"
method, and then to write that string to a file using a standard Cocoa
method such as "writeToFile:atomically:encoding:error:".
There are some script I always want to have loaded in my environment,
ready to use. Fo this, I just add loading instructions in the latent
block (see the documentation).
Blocks also support the standard Cocoa object archiving system
(NSCoding protocol). You can use that too to save your blocks, or even
complex objects graphs (for example, whole collections of blocks). The
difference is that it saves blocks as objects, in some kind of binary
format. In addition to the standards Cocoa method, F-Script offers
some handy extensions for performing this. For instance, try this in F-
Script:

myBlock := [:a :b| a + b].
myBlock save.

Then to load:

sys load

See also the save: and load: methods.

Philippe
Reply all
Reply to author
Forward
0 new messages