Re: [F-Script-talk] Multiple Blocks
Brought to you by:
pmougin
From: Ken F. <ken...@gm...> - 2006-09-08 07:04:36
|
On 9/7/06, Jeremy Sacket <js...@ga...> wrote: > > I am trying to implement extensions into my app. I am wanting to define > blocks in one file and then run only blocks that I call. > Example: > > [ > name:=[ sys log:('Jeremy').] > description:=[ :des| sys log:('des).] > ] > > Now I want to just execute the "name" block. Executing the big outer block will dump a definition for 'name' and 'description' in the enviroment that executes the block. Executing the outer block will not execute the inner blocks. So, you could do this: (typed in gmail, and skipping all the error handling for conciseness. Note that the example string above won't compile as a block.) > -(id)runProcedure > { > // will set fscript to the above example. > NSString *fscript = [procedure objectForKey:@"procedure"]; FSInterpreter *interpreter = [FSInterpreter interpreter]; System *sys = [interpreter objectForIdentifier:@"sys" found:NULL]; Block *outerBlock = [sys blockFromString:fscript]; // block is compiled in the environment of the interpreter [outerBlock value]; //.. so the 'name' identifier is bound in the interpreter Block *nameBlock = [interpreter objectForIdentifier:@"name" found:NULL]; [nameBlock value]; } It might seem a little less indirect if the file contained statements without the big enclosing block. Then you could use -[FSInterpreter execute:] to execute the string, and -[FSInterpreter objectForIdentifier:found:] to retrieve the blocks bound in the interpreter as a result. -Ken |