View Full Version : Pass return statement as argument

04-11-2010, 12:28 AM
I have two procs, one proc has a string return statement and I want to use that as the flag argument for the other. What would be the proper syntax for this?

04-11-2010, 07:58 AM
You'll probably have to wrap the whole thing into an eval because proc1 returns an object.

eval( "proc2( -f " + arg1 + " -f " + proc1( arg2 ) + " );" );

04-11-2010, 10:46 AM
I'm not sure I understand Camden's reply.. either that or I've misunderstood your post Camaro...

you're talking about MEL right?

To capture a procs return params you just use the backticks: ``

global proc string procA()
string $result = ("something"+`rand 50`); // just make a random string
return $result; // return it

global proc procB(string $input)
print ("the passed parameter is: "+$input+"\n");

// to use:
string $str = `procA`;
print $str;


04-11-2010, 09:46 PM
My bad, I was thinking of constructing the flags themselves - although I still didn't put that in my example...

This makes more sense:
proc string proc1() { return "Hello"; }
proc proc2( string $input ) { print ( $input + " world." ); }

proc2( `proc1` );
Hello world.

04-12-2010, 03:49 PM
Another thing to note is that arrays are always considered pass by reference in MEL. So you could do something like this (although it is a bit uglier):

global proc myProc1( string $byRef[] )
$byRef[0] = "test";

global proc myProc2( string $byRef[] )
$byRef[0] = "test2";

string $myString[];
myProc1( $myString );
myProc2( $myString );
print $myString[0];
// Result: test2 //

CGTalk Moderation
04-12-2010, 03:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.