Activating a Function in a Different Stack

Dar Scott dsc at swcp.com
Sun Oct 29 18:12:39 EST 2006


On Oct 29, 2006, at 3:07 PM, Marielle Lange wrote:

> Stack A
> ---------
> 	on mouseup
> 		send doSomething to stack "stackB"
> 		wait 1 tick (in case of, I believe that's not needed but I tend  
> to add it)
> 		put the handlername_result of stack "stackB"  into tResult.    
> <---  reading the custom property of another object
> 	end mouseup
>
> Stack B
> ---------
> 	on doSomething
> 		--  do something
> 		set the dosomething_result of me to the backgroundColor of this  
> stack
> 	end doSomething

I think there is a shortcut.  You can use 'the result' for other than  
errors for custom commands.

Stack A
---------
	on mouseup
		send doSomething to stack "stackB"
		put the result into tResult.
	end mouseup

Stack B
---------
	on doSomething
		--  do something
		return the backgroundColor of this stack
	end doSomething

Another approach that makes sense for some kinds of functions is to  
define a virtual property on stack B.

And--I have recently learned--one way to call a function in another  
object is to temporarily move insert the object into the front  
scripts.  If there is not a problem with a name conflict this can  
also go into the back scripts, or if it is a stack, into the library  
scripts.  On my computer (1.25GHz G4) it takes less than 25  
microseconds to insert and remove an object, though I think stacks  
take longer for some reason.  I had been thinking of this in terms of  
a small library with possible name clashes, but this would work for a  
single function usage.

Stack A
---------
	on mouseup
		insert the script of stack "stackB" into front
		put f(x,y,z) into tResult.
                 remove the script of stack "stackB" from front
	end mouseup

Stack B
---------
	function f x, y, z
		--  do something
		return "done", x, y, z, the backgroundColor of this stack
	end f

The meaning is not exactly the same a similar method using send  
because the message path is changed.

Dar



More information about the Use-livecode mailing list