Get a handler from a script

Mark Smith mark at maseurope.net
Thu Mar 16 22:04:54 EST 2006


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



More information about the use-livecode mailing list