Page 1 of 1

Calling a function in a specific external stack

Posted: Fri Oct 09, 2009 3:32 pm
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?

Posted: Fri Oct 09, 2009 3:39 pm
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

Posted: Fri Oct 09, 2009 4:27 pm
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?

Posted: Fri Oct 09, 2009 6:37 pm
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

Posted: Fri Oct 09, 2009 6:48 pm
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?

Posted: Fri Oct 09, 2009 10:49 pm
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.

Re: Calling a function in a specific external stack

Posted: Sat Oct 10, 2009 8:07 pm
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")

Posted: Sun Oct 11, 2009 1:16 am
by jsims
Thanks, Jacqueline!

More very helpful information.

Posted: Sun Oct 11, 2009 3:27 am
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....