Using handler local variables of caller

Dar Scott dsc at swcp.com
Thu May 3 16:15:00 EDT 2012


Thanks, Ray!  That is just what I wanted!  

I do need to come up with a growth plan for when a future version of LiveCode does break it.  (And maybe by then I'll have my script filter working.)

Dar


On May 3, 2012, at 1:25 PM, Ken Ray wrote:

> 
> On May 1, 2012, at 9:03 PM, Dar Scott wrote:
> 
>> Hi, Mark!
>> 
>> You hit the nail on the head.
>> 
>> You work with desktop externals, right?  They don't have this limitation.  Since iOS externals do have the limitation, I'm not going to go that way.
>> 
>> Here is a goofy solution:
>> 
>> function darzCommand
>> 	get 123
>> 	return "put " & it & " into it"
>> end darzCommand
> 
> Trevor had a great (although sneaky) solution, posted a couple of years back (thank you, Scripter's Scrapbook!):
> 
> He wanted to run a custom handler and have it set the value of "it" independently from "the result". The example he wanted to make work was:
> 
>   GrabSomeWebData
>   put the result into theError
> 
>   if theError is empty then
>      -- 'it' contains the data from the web
>   end if
> 
> To do this, he has a special handler that "GrabSomeWebData" would call that uses the debugcontext to work its magic (I've shortened some of his global names for clarity in email):
> 
>   private command _SetValueOfItInCaller pValue
>      global gTempStorageForHandlerLocalVar
> 
>      ## Store value in global
>      put pValue into gTempStorage
> 
>      ## Store current debugcontext (debugger uses this)
>      put the debugcontext into theContext
> 
>      ## the executionContexts is the list of handlers in the chain.
>      ## This handler would be line -1.
>      ## The handler that called this handler is -2.
>      ## The handler that you want to set "it" in is -3
>      set the debugcontext to line -3 of the executioncontexts
> 
>      ## Make the global gTempStorage available 
>      ## within context of handler we want to set "it" in. Then set it to the 
>      ## global var
>      debugdo "global gTempStorage;put gTempStorage into it"
> 
>      ## restore debugcontext
>      set the debugcontext to theContext
> 
>      ## cleanup
>      delete global gTempStorage
>   end _SetValueOfItInCaller
> 
> I haven't tested it in LC 5.x, but I don't think anything's changed that would prevent it from working,
> 
> Ken Ray
> Sons of Thunder Software, Inc.
> Email: kray at sonsothunder.com
> Web Site: http://www.sonsothunder.com/	
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list