Shay Friedman
2009-Jun-09 16:01 UTC
[Ironruby-core] More Interop Qs (Out, Ref and Structs)
Hi there, I''ve got a few more questions regarding interop scenarios: 1. What happens with out parameters in methods? Currently when I try to use them I get an error: :0: can''t convert String into System::Runtime::CompilerServices::StrongBox[System::String] (TypeError) 2. What happens with ref parameters? it doesn''t throw an error but it doesn''t change the value as well. 3. Structs - they are mapped to Ruby classes, but I can''t create new instances of them using the new method. How should it be done? Thanks and sorry for the question flood :) Shay. ---------------------------- http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/.
Tomas Matousek
2009-Jun-09 17:30 UTC
[Ironruby-core] More Interop Qs (Out, Ref and Structs)
Could you be more specific? It''s not helpful if you just say "it doesn''t work". Can you include code that you are trying to run and the exact result you get? Out parameters are returned in a CLR object array as a return value: has_value, value = dictionary.try_get_value("foo") Thanks, Tomas -----Original Message----- From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman Sent: Tuesday, June 09, 2009 9:02 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] More Interop Qs (Out, Ref and Structs) Hi there, I''ve got a few more questions regarding interop scenarios: 1. What happens with out parameters in methods? Currently when I try to use them I get an error: :0: can''t convert String into System::Runtime::CompilerServices::StrongBox[System::String] (TypeError) 2. What happens with ref parameters? it doesn''t throw an error but it doesn''t change the value as well. 3. Structs - they are mapped to Ruby classes, but I can''t create new instances of them using the new method. How should it be done? Thanks and sorry for the question flood :) Shay. ---------------------------- http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/. _______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Shay Friedman
2009-Jun-09 20:25 UTC
[Ironruby-core] More Interop Qs (Out, Ref and Structs)
No problem, here is the list with more details: 1. out parameters: C# ----- public class Class3 { public void Test1(out string str) { str = "From C#"; } } IronRuby ---------->> s = "a"=> "a">> Class3.new.Test1(s):0: can''t convert String into System::Runtime::CompilerServices::StrongBox[System::String] (TypeError) 2. ref parameters: C# ----- public class Class3 { public void Test2(ref string str) { str = "From C#"; } } IronRuby ---------->>> s = "a"=> "a">>> Class3.new.Test2(s)=> ''From C#''>>> s=> "a" (This seems to work like your description to out parameters) 3. Structs C# ------ public struct FullName { public string FirstName; public string LastName; } IronRuby ----------->>> my_struct = FullName.new:0: allocator undefined for Sample::FullName (TypeError) Let me know if you need more details. Many thanks, Shay ---------------------------- Shay Friedman http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/.
[204] > ir IronRuby 0.5.0.0 on .NET 2.0.50727.4918 Copyright (c) Microsoft Corporation. All rights reserved.>>> require ''temp1''=> true Out:>>> c = Class3.new=> Class3>>> a = c.test1=> ''From C#''>>> a=> ''From C#'' Ref:>>> b = c.test2:0: wrong number of arguments (0 for 1) (ArgumentError)>>> b = "a"=> "a">>> c.test2 b=> ''From C#''>>> c=> Class3>>> b=> "a">>> b = c.test2 b=> ''From C#''>>> b=> ''From C#'' I''ll let Tomas explain refs, since I''m not sure what''s going on. It seems like b = c.test2 should work if b has been defined already, but that may be just me. JD ...there is no try> -----Original Message----- > From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core- > bounces at rubyforge.org] On Behalf Of Shay Friedman > Sent: Tuesday, June 09, 2009 1:25 PM > To: ironruby-core at rubyforge.org > Subject: Re: [Ironruby-core] More Interop Qs (Out, Ref and Structs) > > No problem, here is the list with more details: > > 1. out parameters: > C# > ----- > public class Class3 { > public void Test1(out string str) { > str = "From C#"; > } > } > > IronRuby > ---------- > >> s = "a" > => "a" > >> Class3.new.Test1(s) > :0: can''t convert String into > System::Runtime::CompilerServices::StrongBox[System::String] (TypeError) > > 2. ref parameters: > C# > ----- > public class Class3 { > public void Test2(ref string str) { > str = "From C#"; > } > } > > IronRuby > ---------- > >>> s = "a" > => "a" > >>> Class3.new.Test2(s) > => ''From C#'' > >>> s > => "a" > > (This seems to work like your description to out parameters) > > 3. Structs > C# > ------ > public struct FullName { > public string FirstName; > public string LastName; > } > > IronRuby > ----------- > >>> my_struct = FullName.new > :0: allocator undefined for Sample::FullName (TypeError) > > Let me know if you need more details. > > Many thanks, > Shay > ---------------------------- > Shay Friedman > http://www.ironshay.com > Follow me: http://twitter.com/ironshay > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core
Tomas Matousek
2009-Jun-10 05:19 UTC
[Ironruby-core] More Interop Qs (Out, Ref and Structs)
1), 2) ref/out params C#: bool TryGetValue(string key, out int value) Ruby call: result, value = dict.try_get_value(''key'') I.e. arguments for out parameters are omitted, the values returned via out parameters are stored in an array returned by the method. The return value of the method is the first element of that array and is followed by out and ref parameter return values in the order in which they are declared. Another example: bool Foo(string a, out string b, string c, ref string d, string e, out string f); result, b_out, d_out, f_out = foo(''a_in '', ''c_in '', ''d_in'', ''e_in '') 3) This is a bug. I have a fix for it, so it will work soon. However, I''d strongly recommend not to use mutable structs. The struct data are copied when boxed/unboxed and it might not be obvious where this happens - for example if you pass a struct instance from Ruby to C# method that accepts it as a strongly typed parameter the struct get unboxed and its data are copied. Tomas> -----Original Message----- > 1. out parameters: > C# > ----- > public class Class3 { > public void Test1(out string str) { > str = "From C#"; > } > } > > IronRuby > ---------- > >> s = "a" > => "a" > >> Class3.new.Test1(s) > :0: can''t convert String into > System::Runtime::CompilerServices::StrongBox[System::String] (TypeError)> 2. ref parameters: > C# > ----- > public class Class3 { > public void Test2(ref string str) { > str = "From C#"; > } > } > > IronRuby > ---------- > >>> s = "a" > => "a" > >>> Class3.new.Test2(s) > => ''From C#'' > >>> s > => "a" > > (This seems to work like your description to out parameters) > > 3. Structs > C# > ------ > public struct FullName { > public string FirstName; > public string LastName; > } > > IronRuby > ----------- > >>> my_struct = FullName.new > :0: allocator undefined for Sample::FullName (TypeError) > > Let me know if you need more details. > > Many thanks, > Shay > ---------------------------- > Shay Friedman > http://www.ironshay.com > Follow me: http://twitter.com/ironshay > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core_______________________________________________ Ironruby-core mailing list Ironruby-core at rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core
Shay Friedman
2009-Jun-10 17:10 UTC
[Ironruby-core] More Interop Qs (Out, Ref and Structs)
Thanks Jim! Tomas, do you have an insight about ref params? Thanks, Shay. ---------------------------- Shay Friedman http://www.ironshay.com Follow me: http://twitter.com/ironshay -- Posted via http://www.ruby-forum.com/.