Get a handler from a script

Geoff Canyon gcanyon at inspiredlogic.com
Sat Mar 18 13:12:17 EST 2006


On Mar 17, 2006, at 9:18 PM, Geoff Canyon wrote:

> So change the statement below to:
>
>   if (word 1 of L is among the items of \
>   "on,function,getprop,setprop,--on,--function,--getprop,--setprop"  
> and...etc.) \
>   or (word 1 of L is "--" and \
>   word 2 of L is among the items of "on,function,getprop,setprop"  
> and...etc.)


I rewrote this to handle numerous options. This has been lightly tested.

It should handle all three forms of comments: -- # /*...*/

It should handle all cases where there isn't intervening text, so:

--on myHandler
# function myFunction

/*getProp myProp
end myProp*/

/* setProp myProp
end myProp */

The script editor _hates_ the structure I used. If you format this in  
the script editor, the indentation will be all out of whack. I've  
corrected it here I think (for clarity).

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

As before:

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



More information about the use-livecode mailing list