[IronPython] c# function that passes arguments by reference

Frank Kampas fkampas at msn.com
Sat Aug 26 20:01:35 CEST 2006


Dino,

Yes that works.

I discovered I can also initialize the references to the arrays as follows:

>>> x = clr.Reference[System.Array[float]]((0,0,0))
>>> pi = clr.Reference[System.Array[float]]((0,0,0))
>>> slack = clr.Reference[System.Array[float]]((0,0,0))
>>> dj = clr.Reference[System.Array[float]]((0,0,0))

Thanks for your help on this.

Frank
  ----- Original Message ----- 
  From: Dino Viehland<mailto:dinov at exchange.microsoft.com> 
  To: Discussion of IronPython<mailto:users at lists.ironpython.com> 
  Sent: Friday, August 25, 2006 7:52 PM
  Subject: Re: [IronPython] c# function that passes arguments by reference


  The Reference object is just a holder so that you can pass it in, and then use it after the call.  It has a .Value property that will return you the updated value (or the original if the value hasn't changed).  So x.Value should get you the new value.

   

  From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Frank Kampas
  Sent: Friday, August 25, 2006 2:17 PM
  To: Discussion of IronPython
  Subject: Re: [IronPython] c# function that passes arguments by reference

   

  Ok, that worked but what I got back is not very useful

   

  >>> lpstat = clr.Reference[int](0)
  >>> objval = clr.Reference[float](0)
  >>> x = clr.Reference[System.Array[float]](System.Array[float]((0,0,0)))
  >>> pi = clr.Reference[System.Array[float]](System.Array[float]((0,0,0)))
  >>> sl = clr.Reference[System.Array[float]](System.Array[float]((0,0,0)))
  >>> dj = clr.Reference[System.Array[float]](System.Array[float]((0,0,0)))
  >>> wr.GetResults(lpstat,objval,x,pi,sl,dj)
  True
  >>> x
  <IronPython.Modules.ClrModule+Reference`1[[System.Double[], mscorlib, Version=2.
  0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] object at 0x0000000000
  00002E [Reference(System.Double[])]>
  >>> lpstat
  <IronPython.Modules.ClrModule+Reference`1[[System.Int32, mscorlib, Version=2.0.0
  .0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] object at 0x0000000000000
  02F [Reference(1)]>
  >>>

   

  The approach I found seems to be more useful if it doesn't have some problem that

  would show up for bigger arrays.

   

   

  >>> wr.GetResults(0,0,(0,0,0),(0,0,0),(0,0,0),(0,0,0))
  (True, 1, 13.0, System.Double[](5.0, 4.0, 0.0), System.Double[](0.0, 0.0, -3.062
  5), System.Double[](0.0, 0.0, 0.0), System.Double[](0.0, 0.0625, 0.375))

    ----- Original Message ----- 

    From: Dino Viehland<mailto:dinov at exchange.microsoft.com> 

    To: Discussion of IronPython<mailto:users at lists.ironpython.com> 

    Sent: Friday, August 25, 2006 5:00 PM

    Subject: Re: [IronPython] c# function that passes arguments by reference

     

    You can do:

     

    import System

    import clr

    clr.Reference[System.Array[int]]( System.Array[int]( (1,2,3) ) )

     

     

    This breaks down into the array creation:

    System.Array[int]( (1,2,3) )

     

    And then passing that to the new instance of clr.Reference.  

     

    From: users-bounces at lists.ironpython.com<mailto:users-bounces at lists.ironpython.com> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Frank Kampas
    Sent: Friday, August 25, 2006 1:43 PM
    To: Discussion of IronPython
    Subject: Re: [IronPython] c# function that passes arguments by reference

     

    how to I create an array to pass by reference?  I assume that your example is creating an integer with a value of 3 to pass by reference.

      ----- Original Message ----- 

      From: Dino Viehland<mailto:dinov at exchange.microsoft.com> 

      To: Discussion of IronPython<mailto:users at lists.ironpython.com> 

      Sent: Friday, August 25, 2006 4:06 PM

      Subject: Re: [IronPython] c# function that passes arguments by reference

       

      This is the "easy" way to call functions that are passing values by reference.  You should be able to pass non-zero values as well as non-empty arrays.  The only thing that should disallow this is if there were multiple overloads that resulted in an ambiguous method resolution.  

       

      For these cases there is a generic Reference type defined in the CLR module.  You can use this:

       

      import clr

      x = clr.Reference[int](3)

       

      someObj.someFunction(x)

       

      print x.Value

       

      and Value will be updated after the call.

       

      From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Frank Kampas
      Sent: Friday, August 25, 2006 12:58 PM
      To: users at lists.ironpython.com
      Subject: [IronPython] c# function that passes arguments by reference

       

      If I import a c# function that passes its arguments (integers and arrays)

      by reference, the only way I can get it to work is pass zeroes for the integers and

      arrays of zero for the arrays.  The results for the variables passed by reference return with the function

      return.  Is that what is supposed to occur?  

      _______________________________________________
      users mailing list
      users at lists.ironpython.com<mailto:users at lists.ironpython.com>
      http://lists.ironpython.com/listinfo.cgi/users-ironpython.com<http://lists.ironpython.com/listinfo.cgi/users-ironpython.com>

    _______________________________________________
    users mailing list
    users at lists.ironpython.com<mailto:users at lists.ironpython.com>
    http://lists.ironpython.com/listinfo.cgi/users-ironpython.com<http://lists.ironpython.com/listinfo.cgi/users-ironpython.com>

  _______________________________________________
  users mailing list
  users at lists.ironpython.com
  http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060826/995e4df1/attachment.html>


More information about the Ironpython-users mailing list