Get a handler from a script

Geoff Canyon gcanyon at inspiredlogic.com
Fri Mar 17 11:16:00 EST 2006


On Mar 16, 2006, at 5:25 PM, Thomas McGrath III wrote:

> But, I would like to get just one of the handlers from a script via  
> script:    put handler "FooBar" of the script of card "Foo" into tBar

Most of the solutions presented so far make assumptions. For example,  
there can be more than one space between "on" and the handler name.

In Navigator I use this to retrieve a list of the handler names:

repeat for each line L in tText -- tText is the script
   if word 1 of L is among the items of "on,function,getprop,setprop"  
then
     put L & cr after tMenuText
   end if
end repeat

So to get the handler you would be doing something like:

put 0 into tLineNumber
put false into tEnteredHandler
repeat for each line L in tText -- tText is the script
   add 1 to tLineNumber
   if word 1 of L is among the items of "on,function,getprop,setprop"  
and \
     word 2 of L is tHandlerName then
     put tLineNumber into tStartLineNumber
     put true into tEnteredHandler
   end if
   if tEnteredHandler and \
     word 1 of L is "end" and \
     word 2 of L is tHandlerName then
     put tLineNumber into tEndLineNumber
     exit repeat
   end if
end repeat

-- if tEnteredHandler is false, we didn't find the handler
-- if tEnteredHandler is true, tStartLineNumber is where it starts,
-- tEndLineNumber is where it ends

regards,

Geoff



More information about the Use-livecode mailing list