Hi,
A couple of technical questions regarding how to leverage Ruby from
VB.Net
and vice versa:
-
Is the ScriptScope the only option for passing object refs into Ruby?
I
mean can they also be passed as parameters to the Ruby methods called by
InvokeMember?
-
Ruby has no need for passing parameters “ByRef” like you can in VB
because Ruby’s return statement so naturally returns an arbitrary list
of
objects as an array, and Ruby supports multiple assignment on a single
line.
But I have legacy VB methods with ByRef parameters that really do change
which objects the parameters reference in the caller. I would like to be
able to call these VB methods from Ruby code, but since Ruby has no such
thing as ByRef, I don’t know what kind of behavior I should expect. Can
the
Ruby variables passed as parameters get reassigned by VB code to point
to VB
objects without any additional shenanigans? If not, then is there an
established workaround for ByRef parameters? Has this odd situation been
addressed yet? (I don’t want to rewrite/retest legacy code that already
works just fine).
Thanks,
Julian.
-
Yes, you can pass parameters via InvokeMember.
-
You can call methods with ByRefs from Ruby. An example could be
Dictionary<int, int>.TryGetValue:
dict = System::Collections::Generic::Dictionary[Fixnum, Fixnum].new
=> System.Collections.Generic.Dictionary`2[System.Int32,System.Int32]
dict.add 1,2
=> nil
dict.try_get_value 1
=> [true, 2]
The second parameter to TryGetvalue is an ByRef. You can either
omit an argument for such parameter or pass an instance of
System.Runtime.CompilerServices.StrongBox. If you omit the argument
the result is returned in the return value (as shown above). If you pass
an instance of StrongBox the value is updated in situ.
Similarly for in-out ByRef parameters. You pass in the input value and
either get the output value in the resulting array or the StrongBox
value if you use a StrongBox instance.
Tomas
From: [email protected]
[mailto:[email protected]] On Behalf Of Julian Bishop
Sent: Sunday, June 06, 2010 10:33 PM
To: [email protected]
Subject: [Ironruby-core] VB.Net - Ruby interop
Hi,
A couple of technical questions regarding how to leverage Ruby from
VB.Net and vice versa:
-
Is the ScriptScope the only option for passing object refs into Ruby?
I mean can they also be passed as parameters to the Ruby methods called
by InvokeMember?
-
Ruby has no need for passing parameters “ByRef” like you can in VB
because Ruby’s return statement so naturally returns an arbitrary list
of objects as an array, and Ruby supports multiple assignment on a
single line. But I have legacy VB methods with ByRef parameters that
really do change which objects the parameters reference in the caller. I
would like to be able to call these VB methods from Ruby code, but since
Ruby has no such thing as ByRef, I don’t know what kind of behavior I
should expect. Can the Ruby variables passed as parameters get
reassigned by VB code to point to VB objects without any additional
shenanigans? If not, then is there an established workaround for ByRef
parameters? Has this odd situation been addressed yet? (I don’t want to
rewrite/retest legacy code that already works just fine).
Thanks,
Julian.