edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libs/win32ole.rb;C1200585 File: win32ole.rb =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libs/win32ole.rb;C1200585 (server) 2/26/2010 7:52 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Libs/win32ole.rb;ComConversions @@ -121,13 +121,8 @@ /[{]?[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}[}]?|[0-9A-F]{32}/ =~ str end - # The DLR COM binder only supports core types like System.String as arguments. - # Passing in a Ruby String will not work. So we convert the Ruby types to - # CLR COM interop types as expected by the DLR COM binder def ruby_to_com_interop_type(arg) case arg - when String - arg.to_clr_string when Array element_type = ruby_to_com_interop_type(arg[0]).class converted_elements = ruby_to_com_interop_types arg =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySymbol.cs;C1496258 File: RubySymbol.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySymbol.cs;C1496258 (server) 2/26/2010 7:33 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Builtins/RubySymbol.cs;ComConversions @@ -100,6 +100,10 @@ return _string.GetCharCount(); } + public static explicit operator string(RubySymbol/*!*/ self) { + return self._string.ToString(); + } + #endregion #region IRubyObjectState Members =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;C1594871 File: InteropBinder.cs =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;C1594871 (server) 2/26/2010 7:22 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Runtime/Calls/InteropBinder.cs;ComConversions @@ -24,16 +24,18 @@ using System.Diagnostics; using System.Dynamic; using System.Reflection; -using IronRuby.Compiler; using Microsoft.Scripting.Runtime; using Microsoft.Scripting.Utils; -using IronRuby.Runtime.Conversions; using Microsoft.Scripting.Generation; +using Microsoft.Scripting.Math; +using IronRuby.Builtins; +using IronRuby.Compiler; +using IronRuby.Runtime.Conversions; namespace IronRuby.Runtime.Calls { using Ast = Expression; - using AstUtils = Microsoft.Scripting.Ast.Utils; using AstExpressions = Microsoft.Scripting.Ast.ExpressionCollectionBuilder; + using AstUtils = Microsoft.Scripting.Ast.Utils; internal interface IInteropBinder { RubyContext Context { get; } @@ -128,7 +130,7 @@ DynamicMetaObject errorSuggestion) { #if !SILVERLIGHT DynamicMetaObject result; - if (Microsoft.Scripting.ComInterop.ComBinder.TryBindInvoke(this, target, args, out result)) { + if (Microsoft.Scripting.ComInterop.ComBinder.TryBindInvoke(this, target, GetComArguments(args), out result)) { return result; } #endif @@ -193,7 +195,7 @@ #if !SILVERLIGHT DynamicMetaObject result; - if (Microsoft.Scripting.ComInterop.ComBinder.TryBindInvokeMember(this, target, args, out result)) { + if (Microsoft.Scripting.ComInterop.ComBinder.TryBindInvokeMember(this, target, GetComArguments(args), out result)) { return result; } #endif @@ -492,7 +494,7 @@ #if !SILVERLIGHT DynamicMetaObject result; - if (Microsoft.Scripting.ComInterop.ComBinder.TryBindSetMember(this, target, value, out result)) { + if (Microsoft.Scripting.ComInterop.ComBinder.TryBindSetMember(this, target, GetComArgument(value), out result)) { return result; } #endif @@ -530,7 +532,7 @@ DynamicMetaObject errorSuggestion) { #if !SILVERLIGHT DynamicMetaObject result; - if (Microsoft.Scripting.ComInterop.ComBinder.TryBindGetIndex(this, target, indexes, out result)) { + if (Microsoft.Scripting.ComInterop.ComBinder.TryBindGetIndex(this, target, GetComArguments(indexes), out result)) { return result; } #endif @@ -584,7 +586,7 @@ #if !SILVERLIGHT DynamicMetaObject result; - if (Microsoft.Scripting.ComInterop.ComBinder.TryBindSetIndex(this, target, indexes, value, out result)) { + if (Microsoft.Scripting.ComInterop.ComBinder.TryBindSetIndex(this, target, GetComArguments(indexes), GetComArgument(value), out result)) { return result; } #endif @@ -805,5 +807,54 @@ metaBuilder.Result = delegateFactory.OpCall(AstUtils.Constant(delegateType), Ast.Convert(target.Expression, type)); return true; } + + // TODO: copied from IronPython + internal static DynamicMetaObject/*!*/[]/*!*/ GetComArguments(DynamicMetaObject/*!*/[]/*!*/ args) { + DynamicMetaObject[] res = null; + for (int i = 0; i < args.Length; i++) { + DynamicMetaObject converted = GetComArgument(args[i]); + if (!ReferenceEquals(converted, args[i])) { + if (res == null) { + res = new DynamicMetaObject[args.Length]; + for (int j = 0; j < i; j++) { + res[j] = args[j]; + } + } + + res[i] = converted; + } else if (res != null) { + res[i] = args[i]; + } + } + + return res ?? args; + } + + // TODO: copied from IronPython + internal static DynamicMetaObject/*!*/ GetComArgument(DynamicMetaObject/*!*/ arg) { + if (arg.Value != null) { + Type type = arg.Value.GetType(); + if (type == typeof(BigInteger)) { + return new DynamicMetaObject( + Ast.Convert(AstUtils.Convert(arg.Expression, typeof(BigInteger)), typeof(double)), + BindingRestrictions.GetTypeRestriction(arg.Expression, type) + ); + } else if (type == typeof(MutableString)) { + // TODO: encoding? + return new DynamicMetaObject( + Ast.Convert(AstUtils.Convert(arg.Expression, typeof(MutableString)), typeof(string)), + BindingRestrictions.GetTypeRestriction(arg.Expression, type) + ); + } else if (type == typeof(RubySymbol)) { + // TODO: encoding? + return new DynamicMetaObject( + Ast.Convert(AstUtils.Convert(arg.Expression, typeof(RubySymbol)), typeof(string)), + BindingRestrictions.GetTypeRestriction(arg.Expression, type) + ); + } + } + + return arg; + } } } =================================================================== edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Tests/Interop/com/apps/excel_spec.rb;C1044032 File: excel_spec.rb =================================================================== --- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Tests/Interop/com/apps/excel_spec.rb;C1044032 (server) 2/26/2010 7:58 PM +++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Tests/Interop/com/apps/excel_spec.rb;ComConversions @@ -55,6 +55,16 @@ }.should_not raise_error end + it "converts Ruby string to BSTR" do + @worksheet.cells[1, 1] = 'hello' + @worksheet.cells[1, 1].text.should == 'hello' + end + + it "converts Ruby symbols to BSTR" do + @worksheet.cells[1, 1] = :rubysym + @worksheet.cells[1, 1].text.should == 'rubysym' + end + it "can select ranges" do range = @worksheet.Range('A1','B3') range.Count.should == 6 ===================================================================