Get a handler from a script
Robert Brenstein
rjb at robelko.com
Thu Mar 16 21:11:59 EST 2006
>Hello friends,
>
>I know how to get the script from an objects script via script:
>put the script of card "Foo" into tBar
>
>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
>
>Anyone know how to do this easily?
>
>Thanks
>
>Tom
>
>
>Thomas J McGrath III
>3mcgrath at adelphia.net
something like (not tested; watch line wraps)
put extractHandlerFromScript(the script of cd "Foo","FooBar") into tBar
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
if tHandlerBegin is 0 then put lineOffset("function" &&
pHandlerName & space, pScript) into tFooBar1
if tHandlerBegin is 0 then put lineOffset("function" &&
pHandlerName & cr, pScript) into tFooBar1
if tHandlerBegin is 0 then return empty
put lineOffset("end" && pHandlerName & cr, pScript) into tHandlerEnd
if tHandlerEnd is 0 then put lineOffset("end" && pHandlerName &
space, pScript) into tHandlerEnd
if tHandlerEnd is 0 then return empty
return line tHandlerBegin to tHandlerEnd of pScript
end extractHandlerFromScript
If formatting is not so regular, you may need to account for multiple
spaces between on/function/end and handler name.
Robert
More information about the use-livecode
mailing list