[IronPython] 'out' parameters

Jim Hugunin jimhug at exchange.microsoft.com
Wed May 11 09:18:54 PDT 2005


Martin's response is right, but I'm afraid that the best way to use
these return values might not be obvious to everyone.  Python's tuple
packing and unpacking operations are often used for multiple return
values in standard Python libraries and IronPython should feel the same
way.  Here's how these calls should look in IronPython:

  ret, result = CheckCooperativeLevel()  
  m, i, j, k = C.M()

And for completeness, I'll add that 'ref' parameters are both passed to
the function and returned as an additional return value.

-Jim

Martin Maly wrote:
> The return value and output parameters (if they are in total more than
> one) are returned as tuple:
> 
> namespace N {
>     public class C {
>         public static int M(out int i, out int j, out int k) {
>             i = 20;
>             j = 30;
>             k = 40;
>             return 10;
>         }
>     }
> }
> 
> Python:
> i = C.M()
> print i
> 
> (10, 20, 30, 40)
> 
> If there is just one output of the function (i.e. void function with
one
> out parameter), the value comes back as a function return value.
> 
> Martin
> 
> -----Original Message-----
> From: users-ironpython.com-bounces at lists.ironpython.com
> [mailto:users-ironpython.com-bounces at lists.ironpython.com] On Behalf
Of
> Nick Jacobson
> Sent: Tuesday, May 10, 2005 11:08 PM
> To: users-ironpython.com at lists.ironpython.com
> Subject: [IronPython] 'out' parameters
> 
> How will IronPython deal with functions that, in C#, use an 'out'
> variable?
> 
> For example, in Microsoft.DirectX.Direct3D, this function exists:
> 
> public bool CheckCooperativeLevel(out int result);
> 
> 
> If I call this from IronPython, there's no way that the value of
result
> would be modified, right?  But it needs to be changed within the
> function
> CheckCooperativeLevel, and I need to get the result back!
> 
> Thanks,
> 
> --Nick
> 
> _______________________________________________
> users-ironpython.com mailing list
> users-ironpython.com at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


More information about the users-ironpython.com mailing list