Get a handler from a script

Jim Ault JimAultWins at yahoo.com
Fri Mar 17 00:37:32 EST 2006


Perhaps using 

set the wholematches to true
put lineOffset("on" && pHandlerName, pScript) into tStart
if tStart is 0 then put lineOffset("function" && pHandlerName, pScript) into
tStart
put (lineOffset("end" && pHandlerName, pScript) +1 into tEnd


answer tStart & cr & tEnd

Jim Ault
Las Vegas

On 3/16/06 7:04 PM, "Mark Smith" <mark at maseurope.net> wrote:

> The reason I think Roberts is more the ticket is that it deals with
> the case where you have a handler 'jumpHigh' as well as a handler
> 'jump' later in the script -- this means we need to check for the end
> of the handler name - which could be a space if there are parameters,
> or cr if not.
> 
> We can avoid checking that for the 'end' line by using the third
> parameter to lineOffset -- lines to skip, so a revised version might
> be:
> 
> function extractHandlerFromScript pScript,pHandlerName
>   put lineOffset("on" && pHandlerName & space, pScript) into tHandlerBegin
>   if tHandlerBegin is 0 then put lineOffset("on" && pHandlerName & cr,
> pScript) into tFooBar1
> -- this deals with either space or cr at the end of the handler name
> -- and we don't need to check for 'function' since it contains 'on'
> 
>   if tHandlerBegin is 0 then return empty
>   put lineOffset("end" && pHandlerName,pScript,tHandlerBegin) into tHandlerEnd
>   if pHandlerEnd is 0 then return empty 
>   return line tHandlerBegin to tHandlerEnd of pScript
> end extractHandlerFromScript
> 
> Cheers,
> 
> Mark
> 
> On 17 Mar 2006, at 02:48, Thomas McGrath III wrote:
> 
> Mark and Robert,
> 
> I needed to check for functions as well. So I adapted the script from
> Mark into this:
> 
> function getHandlers hName,tControl
>     put the script of card tControl into tScript
>     put tScript
>     get lineOffset("on " & hName,tScript)
>     if it = 0 then
>         get lineOffset("function " & hName,tScript)
>     end if
>     if it = 0 then return "not found"
>     put it into startLine
>     get lineOffset("end " & hName,tScript)
>     return line startLine to it of tScript
> end getHandlers
> 
> Thank you so much for your help,
> 
> Tom
> 
> 
> On Mar 16, 2006, at 9:16 PM, Mark Smith wrote:
> 
> Not tested, but something like this should work:
> 
> function getHandler hName,tControl
>   put the script of control tControl into tScript
>   get lineOffset("on " & hName,tScript)
>   if it = 0 then return "not found"
>   put it into startLine
>   get lineOffset("end " & hName,tScript)
>   return line startLine to it of tScript
> end getHandler
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list