Console container for put function?

Richard Gaskin ambassador at fourthworld.com
Fri Apr 24 11:22:32 EDT 2015


Peter Wood wrote:

 > I’m planning on writing some library functions for testing that can
 > be called from either a GUI stack or a server script. When called
 > from a GUI script it will display its results in a Field, when called
 > from a server script it will displays its result in the console.
 >
 > I’m trying to find a better way than:
 >
 >	if the environment is “server” then
 >		put tResult
 >	else
 >		put tResult after Field tReport
 >	end

Two options come to mind, each with their own tradeoffs:

1. Custom "put" handler
You could use something like "MyPut" instead of "put", so the branching 
is in just one place.  Easy to write, but difficult to accommodate since 
it would mean changing every place you currently use "put".

2. revMessageBoxRedirect
That's a global property which is empty by default, and when empty "put" 
output goes to stdOut when faceless and to a stack named "Message Box" 
when in the IDE as you found.  But when set to the long ID of any 
object, that object will then receive "msgChanged" messages for any puts 
which could be handled however you like, such as displaying the msg 
string in a field in your own stack.

The downside with the latter is that as long as the 
revMessageBoxRedirect is not empty, you'll be responsible for handling 
all Message Box actions; that is, you'll lose the IDE's Message Box as a 
place for output, for any and all scripts that might otherwise "put" to it.

But if that's what you're looking for, revMessageBoxRedirect can be 
handy.  I have a Message Box replacement that uses it and it's been a 
godsend.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.coms




More information about the use-livecode mailing list