Calling a function in a specific external stack

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jsims
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 25
Joined: Thu Apr 30, 2009 1:45 pm
Contact:

Calling a function in a specific external stack

Post by jsims »

Hello All,

This is a little bit of a follow-up to my "malicious code" post. http://forums.runrev.com/phpBB2/viewtopic.php?t=3806

I'm trying to figure out how to call a function in a specific external stack (note the word specific). This is because I would like my two external stacks to use the same function name in order to keep the code generic/consistent.

Example scenario:
Three stacks - MyRevApp.exe, BusinessLayer.rev, DataLayer.rev

In BusinessLayer.rev and DataLayer.rev, I'd like to have a function called StackIsValid(). So, MyRevApp.exe opens the two stacks and I want to call the StackIsValid() function in each. I cannot figure out how to tell Rev which stack to call the function for. I was hoping for something like:

Code: Select all

put StackIsValid() of stack "BusinessLayer" into tValid1
put StackIsValid() of stack "DataLayer" into tValid2
but I can't seem to find a form where that works. The workarounds I have found (and these may be the actual solutions) are:

1) Use a getProp instead of a function (though I'm not sure of any limitations this would result in that are not incurred using a function)
2) Create a handler in the external stacks, use "send" (or "dispatch", though I want an error if the handler doesn't exist and it is my understanding that "dispatch" would eat such an error) to execute the handler in each stack, then check "the result".

Any more good tips from you long-timers?
- John
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld »

See the "call" command in the RevTalk dictionary for a handy way to call handlers outside of the message path.

You may also consider having those stacks inserted into the message path as libraries so their handlers are always available whenever you need them.

This article on extending the message path may be helpful:
http://www.fourthworld.com/embassy/arti ... _path.html
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
jsims
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 25
Joined: Thu Apr 30, 2009 1:45 pm
Contact:

Post by jsims »

Hi Richard,

Thanks for the reply. I did read your article earlier. Very helpful.

My understanding is that "call" only works with handlers, not functions. Also, I didn't see any way for "call" to handle a return value.

Is my understanding correct?
- John
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder »

Seems like the getProp idea may suit your needs best, if I get what you've got in mind. That would probably give you the best polymorphism approach. Something like (untested):

Code: Select all

put the StackIsValid of stack "BusinessLayer" into tValid1
-- then in stack "BusinessLayer.rev":

Code: Select all

getProp StackIsValid
  return IsValid()
end StackIsValid

private IsValid
  -- blah blah blah
  return something
end IsValid
jsims
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 25
Joined: Thu Apr 30, 2009 1:45 pm
Contact:

Post by jsims »

That's exactly what I was leaning towards doing. Do you know if there are any limitations to a getProp that a function does not have? Or vise-versa?
- John
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Post by mwieder »

No limitations to getProp that I can think of offhand other than that you can't do anything like function arguments. And that using getProp that way is a little non-standard, so comment things well.
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Calling a function in a specific external stack

Post by jacque »

jsims wrote:
I'm trying to figure out how to call a function in a specific external stack (note the word specific). This is because I would like my two external stacks to use the same function name in order to keep the code generic/consistent.
You can do it by using this syntax:

get value("myFunction()",stack "externalStack")
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
jsims
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 25
Joined: Thu Apr 30, 2009 1:45 pm
Contact:

Post by jsims »

Thanks, Jacqueline!

More very helpful information.
- John
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld »

jsims wrote:My understanding is that "call" only works with handlers, not functions. Also, I didn't see any way for "call" to handle a return value.
Handlers can return a value, accessed by the caller in "the result".

Given that functions can perform actions and commands can return values, I sometime wonder why there are both types....
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Post Reply