From m.m at upplopp.se Wed Jun 1 15:55:41 2011 From: m.m at upplopp.se (Martin Mazur) Date: Wed, 1 Jun 2011 21:55:41 +0200 Subject: [Ironruby-core] Wiki on GitHub Message-ID: Hello, who is responsible for the wiki on GitHub? Some of the information os terribly misleading and out of date. How would one go about fixing it? //M -- phone: +46 (0)709 78 40 03 e-mail: m.m at upplopp.se twitter: http://twitter.com/m_mazur From jdhardy at gmail.com Wed Jun 1 16:32:06 2011 From: jdhardy at gmail.com (Jeff Hardy) Date: Wed, 1 Jun 2011 13:32:06 -0700 Subject: [Ironruby-core] Wiki on GitHub In-Reply-To: References: Message-ID: I don't think anybody in particular is responsible for it (the IronPython stuff needs an overhaul as well...). I think anyone (with a github account) can edit the wiki, so give it a try and see if that works. - Jeff On Wed, Jun 1, 2011 at 12:55 PM, Martin Mazur wrote: > Hello, > > who is responsible for the wiki on GitHub? > > Some of the information os terribly misleading and out of date. How would one go about fixing it? > > //M > -- > phone: +46 (0)709 78 40 03 > e-mail: m.m at upplopp.se > twitter: http://twitter.com/m_mazur > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > From jschementi at gmail.com Wed Jun 1 16:50:08 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Wed, 1 Jun 2011 16:50:08 -0400 Subject: [Ironruby-core] Wiki on GitHub In-Reply-To: References: Message-ID: What's so misleading or "terribly" out of date? There may be some python stuff missing, but I'm pretty sure everything is still valid. ~Jimmy On Jun 1, 2011, at 4:32 PM, Jeff Hardy wrote: > I don't think anybody in particular is responsible for it (the > IronPython stuff needs an overhaul as well...). I think anyone (with a > github account) can edit the wiki, so give it a try and see if that > works. > > - Jeff > > On Wed, Jun 1, 2011 at 12:55 PM, Martin Mazur wrote: >> Hello, >> >> who is responsible for the wiki on GitHub? >> >> Some of the information os terribly misleading and out of date. How would one go about fixing it? >> >> //M >> -- >> phone: +46 (0)709 78 40 03 >> e-mail: m.m at upplopp.se >> twitter: http://twitter.com/m_mazur >> >> _______________________________________________ >> 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 From m.m at upplopp.se Wed Jun 1 17:08:16 2011 From: m.m at upplopp.se (Martin Mazur) Date: Wed, 1 Jun 2011 23:08:16 +0200 Subject: [Ironruby-core] Wiki on GitHub In-Reply-To: References: Message-ID: <1998A959-9D6F-4677-98DB-BDBF39A6308D@upplopp.se> I stand corrected. I was almost certain I couldn't edit it. *crawls back into his corner* The information I'm referring to is mostly IronRuby on Mono stuff. It refers to repositories that don't exist and build processes that don't work. I'm currently working with Wayne from rvm to get IronRuby on RVM and it's been a bit of a head scratcher. Hopefully we'll get it working soon. I'll update the wiki with new mono build info. Thanks for slapping me straight! //M On 1 jun 2011, at 22.50, Jimmy Schementi wrote: > What's so misleading or "terribly" out of date? There may be some python stuff missing, but I'm pretty sure everything is still valid. > > ~Jimmy > > > On Jun 1, 2011, at 4:32 PM, Jeff Hardy wrote: > >> I don't think anybody in particular is responsible for it (the >> IronPython stuff needs an overhaul as well...). I think anyone (with a >> github account) can edit the wiki, so give it a try and see if that >> works. >> >> - Jeff >> >> On Wed, Jun 1, 2011 at 12:55 PM, Martin Mazur wrote: >>> Hello, >>> >>> who is responsible for the wiki on GitHub? >>> >>> Some of the information os terribly misleading and out of date. How would one go about fixing it? >>> >>> //M >>> -- >>> phone: +46 (0)709 78 40 03 >>> e-mail: m.m at upplopp.se >>> twitter: http://twitter.com/m_mazur >>> >>> _______________________________________________ >>> 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 > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core -- phone: +46 (0)709 78 40 03 e-mail: m.m at upplopp.se twitter: http://twitter.com/m_mazur From thibaut.barrere at gmail.com Thu Jun 2 15:40:23 2011 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Thu, 2 Jun 2011 21:40:23 +0200 Subject: [Ironruby-core] Wiki on GitHub In-Reply-To: <1998A959-9D6F-4677-98DB-BDBF39A6308D@upplopp.se> References: <1998A959-9D6F-4677-98DB-BDBF39A6308D@upplopp.se> Message-ID: Hi Martin, I'm currently working with Wayne from rvm to get IronRuby on RVM and it's > been a bit of a head scratcher. Hopefully we'll get it working soon. I'll > update the wiki with new mono build info. > If you need some extra help testing this, send me an email ; I'm using RVM on the Mac daily. -- Thibaut -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.m at upplopp.se Fri Jun 3 04:04:45 2011 From: m.m at upplopp.se (Martin Mazur) Date: Fri, 3 Jun 2011 10:04:45 +0200 Subject: [Ironruby-core] Wiki on GitHub In-Reply-To: References: <1998A959-9D6F-4677-98DB-BDBF39A6308D@upplopp.se> Message-ID: <08F0791D-B00D-4608-B6EB-54C924029DA5@upplopp.se> Awesome! I'll post to the mailing list once we have something working. Thanks! On 2 jun 2011, at 21:40, Thibaut Barr?re wrote: > Hi Martin, > > I'm currently working with Wayne from rvm to get IronRuby on RVM and it's been a bit of a head scratcher. Hopefully we'll get it working soon. I'll update the wiki with new mono build info. > > If you need some extra help testing this, send me an email ; I'm using RVM on the Mac daily. > > -- Thibaut > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: From m.m at upplopp.se Sun Jun 5 12:45:12 2011 From: m.m at upplopp.se (Martin Mazur) Date: Sun, 5 Jun 2011 18:45:12 +0200 Subject: [Ironruby-core] require 'rubygems' gives llformed requirement [">= 0"] (ArgumentError) Message-ID: Hello, When I try to require 'rubygems' in IronRuby on mono (OSX) I get the following error mono ir.exe -e "require 'rubygems'" /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:72:in `parse': Illformed requirement [">= 0"] (ArgumentError) from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `map!' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' from mscorlib:0:in `invoke_object__this___Func`4_object_Proc_object' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:53:in `default' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201:in `require' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201 from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8:in `require' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8 from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088:in `require' from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088 from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' I've tried this with the IronRuby that ships with mono 2.10 binaries for OSX and I've also built IronRuby v1.1.2 and v1.1.3 from source. I get the same error in all three versions. Has anyone else experience this and knows what the issue might be? //M -- phone: +46 (0)709 78 40 03 e-mail: m.m at upplopp.se twitter: http://twitter.com/m_mazur From michael.letterle at gmail.com Fri Jun 10 23:48:49 2011 From: michael.letterle at gmail.com (Michael Letterle) Date: Fri, 10 Jun 2011 23:48:49 -0400 Subject: [Ironruby-core] require 'rubygems' gives llformed requirement [">= 0"] (ArgumentError) In-Reply-To: References: Message-ID: This appears to be a result of the following mono bug: https://bugzilla.novell.com/show_bug.cgi?id=541823 The specific issue is that the regex: (?-six:\A[\s]*(=|!=|>|<|>=|<=|~>)?[\s]*([0-9]+(\.[0-9a-zA-Z]+)*)[\s]*\z) Does not match ">= 0" in mono but does match on .NET This is a mono bug, not an ironruby bug. On Sun, Jun 5, 2011 at 12:45 PM, Martin Mazur wrote: > Hello, > > When I try to require 'rubygems' in IronRuby on mono (OSX) I get the following error > > mono ir.exe -e "require 'rubygems'" > > /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:72:in `parse': Illformed requirement [">= 0"] (ArgumentError) > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `map!' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' > ? ? ? ?from mscorlib:0:in `invoke_object__this___Func`4_object_Proc_object' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:53:in `default' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201:in `require' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201 > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8:in `require' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8 > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088:in `require' > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088 > ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' > > I've tried this with the IronRuby that ships with mono 2.10 binaries for OSX and I've also built IronRuby v1.1.2 and v1.1.3 from source. I get the same error in all three versions. Has anyone else experience this and knows what the issue might be? > > //M > > -- > phone: +46 (0)709 78 40 03 > e-mail: m.m at upplopp.se > twitter: http://twitter.com/m_mazur > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > -- Michael Letterle ----------//----------- http://blog.prokrams.com From michael.letterle at gmail.com Sat Jun 11 00:13:32 2011 From: michael.letterle at gmail.com (Michael Letterle) Date: Sat, 11 Jun 2011 00:13:32 -0400 Subject: [Ironruby-core] require 'rubygems' gives llformed requirement [">= 0"] (ArgumentError) In-Reply-To: References: Message-ID: FWIW, the issue only appears to manifest itself when later sequences in a '|' group are substrings of earlier squences. So, for instance if you move |>|< to the end of the group it appears to work: (?-six:\A[\s]*(=|!=|>=|<=|~>|>|<)?[\s]*([0-9]+(\.[0-9a-zA-Z]+)*)[\s]*\z) Editing the rubygems/requirement.rb file as follows allows rubygems to load: diff --git a/Languages/Ruby/StdLib/ruby/1.9.1/rubygems/requirement.rb b/Languages/Ruby/StdLib/ruby/1.9.1/rubygems/requirement. index d51bf8f..b47859e 100644 --- a/Languages/Ruby/StdLib/ruby/1.9.1/rubygems/requirement.rb +++ b/Languages/Ruby/StdLib/ruby/1.9.1/rubygems/requirement.rb @@ -10,10 +10,10 @@ class Gem::Requirement OPS = { #:nodoc: "=" => lambda { |v, r| v == r }, "!=" => lambda { |v, r| v != r }, - ">" => lambda { |v, r| v > r }, - "<" => lambda { |v, r| v < r }, ">=" => lambda { |v, r| v >= r }, "<=" => lambda { |v, r| v <= r }, + ">" => lambda { |v, r| v > r }, + "<" => lambda { |v, r| v < r }, "~>" => lambda { |v, r| v = v.release; v >= r && v < r.bump } } No promises on the issue not creeping up down the road though... On Fri, Jun 10, 2011 at 11:48 PM, Michael Letterle wrote: > This appears to be a result of the following mono bug: > https://bugzilla.novell.com/show_bug.cgi?id=541823 > > The specific issue is that the regex: > (?-six:\A[\s]*(=|!=|>|<|>=|<=|~>)?[\s]*([0-9]+(\.[0-9a-zA-Z]+)*)[\s]*\z) > Does not match ">= 0" in mono but does match on .NET > > This is a mono bug, not an ironruby bug. > > On Sun, Jun 5, 2011 at 12:45 PM, Martin Mazur wrote: >> Hello, >> >> When I try to require 'rubygems' in IronRuby on mono (OSX) I get the following error >> >> mono ir.exe -e "require 'rubygems'" >> >> /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:72:in `parse': Illformed requirement [">= 0"] (ArgumentError) >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `map!' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' >> ? ? ? ?from mscorlib:0:in `invoke_object__this___Func`4_object_Proc_object' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:97:in `initialize' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/requirement.rb:53:in `default' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201:in `require' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/specification.rb:1201 >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8:in `require' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/source_index.rb:8 >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088:in `require' >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems.rb:1088 >> ? ? ? ?from /Library/Frameworks/Mono.framework/Versions/2.10.1/lib/ironruby/bin/../Lib/ruby/1.9.1/rubygems/custom_require.rb:29:in `require' >> >> I've tried this with the IronRuby that ships with mono 2.10 binaries for OSX and I've also built IronRuby v1.1.2 and v1.1.3 from source. I get the same error in all three versions. Has anyone else experience this and knows what the issue might be? >> >> //M >> >> -- >> phone: +46 (0)709 78 40 03 >> e-mail: m.m at upplopp.se >> twitter: http://twitter.com/m_mazur >> >> _______________________________________________ >> Ironruby-core mailing list >> Ironruby-core at rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> > > > > -- > Michael Letterle > ----------//----------- > http://blog.prokrams.com > -- Michael Letterle ----------//----------- http://blog.prokrams.com From jschementi at gmail.com Sun Jun 12 14:32:16 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Sun, 12 Jun 2011 14:32:16 -0400 Subject: [Ironruby-core] Send your IronRuby usage and quotes In-Reply-To: <16A7DD08F0425648AB80B28A3453C40BDEDFBB@NW60R2.napa.fi> References: <62f0df8b1419e3b7c6c754a5b16aae8d@ruby-forum.com> <16A7DD08F0425648AB80B28A3453C40BDEDFBB@NW60R2.napa.fi> Message-ID: Dug this old thread up and added the posts to https://github.com/IronLanguages/main/wiki/IronLanguage-usages; if you have anything to add, feel free to add it to the wiki page directly. ~Jimmy From m.m at upplopp.se Mon Jun 13 15:44:19 2011 From: m.m at upplopp.se (Martin Mazur) Date: Mon, 13 Jun 2011 21:44:19 +0200 Subject: [Ironruby-core] require 'rubygems' gives llformed requirement [">= 0"] (ArgumentError) In-Reply-To: References: Message-ID: <04D6F342-E67B-45E3-A478-4E41773F812E@upplopp.se> > This appears to be a result of the following mono bug: > https://bugzilla.novell.com/show_bug.cgi?id=541823 Thank you! This helps me a lot. //M From sb at dev-heaven.net Tue Jun 14 11:38:06 2011 From: sb at dev-heaven.net (Sickboy) Date: Tue, 14 Jun 2011 17:38:06 +0200 Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Message-ID: Hello, I recently stumbled upon this awesome code: http://rubyforge.org/pipermail/ironruby-core/2008-December/003377.html It does exactly what I need; dynamically wrapping my RubyObject into a CLR class with CLR properties, except that it?s designed only for string properties. I?ve adjusted the code to support a number of types, incl int, bool and float. However the CLR crashes when-ever I assign a value to a non-string property, e.g float or int. ?The runtime has encountered a fatal error. The address of the error was at 0x5935788d, on thread 0x1adc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.? Any assistance would be deeply appreciated. In essence, instead of using typeof(string) inside the TypeGenerator.Generate method, i use e.g; typeof(int) or typeof(float) This is my current code: C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Reflection.Emit; namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby Code: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < From Tomas.Matousek at microsoft.com Tue Jun 14 12:05:04 2011 From: Tomas.Matousek at microsoft.com (Tomas Matousek) Date: Tue, 14 Jun 2011 16:05:04 +0000 Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties In-Reply-To: References: Message-ID: <9597F4A19BFDB342B6E90963100C33080AF4795E@SN2PRD0302MB113.namprd03.prod.outlook.com> My guess would be that you?re not boxing the value. You need to emit OpCodes.Box to convert bool/int/? to an Object before calling Invoke in setter. The setter should also return Object (your?s is void). In getter you need to use OpCodes.Unbox before returning. I?d also recommend using Func<> delegate instead of your custom delegate types if possible. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Sickboy Sent: Tuesday, June 14, 2011 8:38 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Hello, I recently stumbled upon this awesome code: http://rubyforge.org/pipermail/ironruby-core/2008-December/003377.html It does exactly what I need; dynamically wrapping my RubyObject into a CLR class with CLR properties, except that it?s designed only for string properties. I?ve adjusted the code to support a number of types, incl int, bool and float. However the CLR crashes when-ever I assign a value to a non-string property, e.g float or int. ?The runtime has encountered a fatal error. The address of the error was at 0x5935788d, on thread 0x1adc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.? Any assistance would be deeply appreciated. In essence, instead of using typeof(string) inside the TypeGenerator.Generate method, i use e.g; typeof(int) or typeof(float) This is my current code: C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Reflection.Emit; namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby Code: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < From sb at dev-heaven.net Tue Jun 14 13:03:00 2011 From: sb at dev-heaven.net (Sickboy) Date: Tue, 14 Jun 2011 19:03:00 +0200 Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties In-Reply-To: <9597F4A19BFDB342B6E90963100C33080AF4795E@SN2PRD0302MB113.namprd03.prod.outlook.com> References: <9597F4A19BFDB342B6E90963100C33080AF4795E@SN2PRD0302MB113.namprd03.prod.outlook.com> Message-ID: Thanks! Still new to .NET and especially this stuff. The Box/Unbox seems to have worked, except that if I set e.g 35 as new value, when reading the value back, something completely different comes back, e.g; 150007660, but correct class Fixnum. This number seems randomized, and changes upon accessing the getter for the property more than once. Any suggestions or alternatives welcome. My backup plan is to generate the C# classes from Ruby dynamically during development and saving them into a .cs file to be compiled with exe/dll. Regards From: Tomas Matousek Sent: Tuesday, June 14, 2011 6:05 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] WPF Databinding with RubyObjects, continuation,dynamically create wrappers with strong typed properties My guess would be that you?re not boxing the value. You need to emit OpCodes.Box to convert bool/int/? to an Object before calling Invoke in setter. The setter should also return Object (your?s is void). In getter you need to use OpCodes.Unbox before returning. I?d also recommend using Func<> delegate instead of your custom delegate types if possible. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Sickboy Sent: Tuesday, June 14, 2011 8:38 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Hello, I recently stumbled upon this awesome code: http://rubyforge.org/pipermail/ironruby-core/2008-December/003377.html It does exactly what I need; dynamically wrapping my RubyObject into a CLR class with CLR properties, except that it?s designed only for string properties. I?ve adjusted the code to support a number of types, incl int, bool and float. However the CLR crashes when-ever I assign a value to a non-string property, e.g float or int. ?The runtime has encountered a fatal error. The address of the error was at 0x5935788d, on thread 0x1adc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.? Any assistance would be deeply appreciated. In essence, instead of using typeof(string) inside the TypeGenerator.Generate method, i use e.g; typeof(int) or typeof(float) This is my current code: C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Reflection.Emit; namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby Code: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < From Tomas.Matousek at microsoft.com Tue Jun 14 13:49:41 2011 From: Tomas.Matousek at microsoft.com (Tomas Matousek) Date: Tue, 14 Jun 2011 17:49:41 +0000 Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties In-Reply-To: References: <9597F4A19BFDB342B6E90963100C33080AF4795E@SN2PRD0302MB113.namprd03.prod.outlook.com> Message-ID: <9597F4A19BFDB342B6E90963100C33080AF47A9A@SN2PRD0302MB113.namprd03.prod.outlook.com> Your backup plan might actually be better ? emitting code at runtime is definitely slower than loading already compiled code. You?re still emitting some wrong instructions. Can you send your new code? Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Sickboy Sent: Tuesday, June 14, 2011 10:03 AM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Thanks! Still new to .NET and especially this stuff. The Box/Unbox seems to have worked, except that if I set e.g 35 as new value, when reading the value back, something completely different comes back, e.g; 150007660, but correct class Fixnum. This number seems randomized, and changes upon accessing the getter for the property more than once. Any suggestions or alternatives welcome. My backup plan is to generate the C# classes from Ruby dynamically during development and saving them into a .cs file to be compiled with exe/dll. Regards From: Tomas Matousek Sent: Tuesday, June 14, 2011 6:05 PM To: ironruby-core at rubyforge.org Subject: Re: [Ironruby-core] WPF Databinding with RubyObjects, continuation,dynamically create wrappers with strong typed properties My guess would be that you?re not boxing the value. You need to emit OpCodes.Box to convert bool/int/? to an Object before calling Invoke in setter. The setter should also return Object (your?s is void). In getter you need to use OpCodes.Unbox before returning. I?d also recommend using Func<> delegate instead of your custom delegate types if possible. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Sickboy Sent: Tuesday, June 14, 2011 8:38 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Hello, I recently stumbled upon this awesome code: http://rubyforge.org/pipermail/ironruby-core/2008-December/003377.html It does exactly what I need; dynamically wrapping my RubyObject into a CLR class with CLR properties, except that it?s designed only for string properties. I?ve adjusted the code to support a number of types, incl int, bool and float. However the CLR crashes when-ever I assign a value to a non-string property, e.g float or int. ?The runtime has encountered a fatal error. The address of the error was at 0x5935788d, on thread 0x1adc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.? Any assistance would be deeply appreciated. In essence, instead of using typeof(string) inside the TypeGenerator.Generate method, i use e.g; typeof(int) or typeof(float) This is my current code: C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Reflection.Emit; namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby Code: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < http://rubyforge.org/mailman/listinfo/ironruby-core -------------- next part -------------- An HTML attachment was scrubbed... URL: From sb at dev-heaven.net Tue Jun 14 13:56:14 2011 From: sb at dev-heaven.net (Sickboy) Date: Tue, 14 Jun 2011 19:56:14 +0200 Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties In-Reply-To: <9597F4A19BFDB342B6E90963100C33080AF47A9A@SN2PRD0302MB113.namprd03.prod.outlook.com> References: <9597F4A19BFDB342B6E90963100C33080AF4795E@SN2PRD0302MB113.namprd03.prod.outlook.com> <9597F4A19BFDB342B6E90963100C33080AF47A9A@SN2PRD0302MB113.namprd03.prod.outlook.com> Message-ID: Thanks! Currently on my way with the backup plan. But here?s the C# and Ruby for the dynamic implementation: C# namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); if (type != typeof(string)) { //ilGen.Emit(OpCodes.Unbox, type); } ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); if (type == typeof(int) || type == typeof(float)) { ilGen.Emit(OpCodes.Box, type); } ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < delegate instead of your custom delegate types if possible. Tomas From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Sickboy Sent: Tuesday, June 14, 2011 8:38 AM To: ironruby-core at rubyforge.org Subject: [Ironruby-core] WPF Databinding with RubyObjects, continuation, dynamically create wrappers with strong typed properties Hello, I recently stumbled upon this awesome code: http://rubyforge.org/pipermail/ironruby-core/2008-December/003377.html It does exactly what I need; dynamically wrapping my RubyObject into a CLR class with CLR properties, except that it?s designed only for string properties. I?ve adjusted the code to support a number of types, incl int, bool and float. However the CLR crashes when-ever I assign a value to a non-string property, e.g float or int. ?The runtime has encountered a fatal error. The address of the error was at 0x5935788d, on thread 0x1adc. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.? Any assistance would be deeply appreciated. In essence, instead of using typeof(string) inside the TypeGenerator.Generate method, i use e.g; typeof(int) or typeof(float) This is my current code: C#: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; using System.Reflection.Emit; namespace GenerateType { public class TypeGenerator { public delegate object GetPropertyDelegate(string propertyName); public delegate object SetPropertyDelegate(string propertyName, object value); public static Type Generate(string className, Dictionary> properties) { AssemblyName asmName = new AssemblyName("BindingTypes"); AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run); ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("Types"); TypeBuilder typeBuilder = modBuilder.DefineType(className, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); FieldBuilder getFieldBuilder = typeBuilder.DefineField("OnGet", typeof(GetPropertyDelegate), FieldAttributes.Public); FieldBuilder setFieldBuilder = typeBuilder.DefineField("OnSet", typeof(SetPropertyDelegate), FieldAttributes.Public); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig; Type type = null; foreach (string s in properties.Keys) { type = null; switch (s) { case "float": type = typeof(float); break; case "int": type = typeof(int); break; case "string": type = typeof(string); break; case "bool": type = typeof(bool); break; //case "dynamic": // type = dynamic; } if (type != null) { GenerateProperties(properties[s], type, typeBuilder, getSetAttr, getFieldBuilder, setFieldBuilder); } } return typeBuilder.CreateType(); } public static void GenerateProperties(List properties, Type type, TypeBuilder typeBuilder, MethodAttributes getSetAttr, FieldBuilder getFieldBuilder, FieldBuilder setFieldBuilder) { foreach (string propertyName in properties) { PropertyBuilder propBuilder = typeBuilder.DefineProperty(propertyName, PropertyAttributes.None, typeof(object), new Type[] {}); MethodBuilder getter = typeBuilder.DefineMethod("get_" + propertyName, getSetAttr, type, Type.EmptyTypes); ILGenerator ilGen = getter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, getFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Callvirt, typeof(GetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Ret); // Define the "set" accessor method for CustomerName. MethodBuilder setter = typeBuilder.DefineMethod("set_" + propertyName, getSetAttr, null, new Type[] { type }); ilGen = setter.GetILGenerator(); ilGen.Emit(OpCodes.Ldarg_0); ilGen.Emit(OpCodes.Ldfld, setFieldBuilder); ilGen.Emit(OpCodes.Ldstr, propertyName); ilGen.Emit(OpCodes.Ldarg_1); ilGen.Emit(OpCodes.Callvirt, typeof(SetPropertyDelegate).GetMethod("Invoke")); ilGen.Emit(OpCodes.Pop); ilGen.Emit(OpCodes.Ret); // Last, we must map the two methods created above to our PropertyBuilder to // their corresponding behaviors, "get" and "set" respectively. propBuilder.SetGetMethod(getter); propBuilder.SetSetMethod(setter); } } } } Ruby Code: include System::Data include System::Windows::Data include System::ComponentModel include GenerateType class WrapperGenerator def initialize @wrapper_cache = {} end def wrap(ruby_object) if ruby_object.is_a? Array ruby_object.map {|o| wrap(o) } else cache(ruby_object) unless cached(ruby_object) wrapper_class = cached(ruby_object) wrapper_class.new(ruby_object) end end def invalidate @wrapper_cache.clear end private def cached(object) @wrapper_cache[object.class.name] end def cache(object) @wrapper_cache[object.class.name] = generate_wrapper(object) end def generate_wrapper(object) wrapper_name = "#{object.class.name}Wrapper" properties = Dictionary.of(System::String, List.of(System::String)).new if defined?(object.class::PROPERTY_DESCRIPTORS) object.class::PROPERTY_DESCRIPTORS.each_pair do |k, v| properties[k.to_clr_string] = List.of(System::String).new properties[k.to_clr_string].replace v.map{|e| e.to_clr_string} end else # Default to String properties properties["string"] = List.of(System::String).new properties["string"].replace (object.methods - Object.instance_methods).map{|e| e.to_clr_string} end wrapper_base_type = TypeGenerator.generate("#{wrapper_name}Base", properties) base_instance = System::Activator.create_instance wrapper_base_type eval < From JacquesD at korbitec.com Wed Jun 15 10:42:28 2011 From: JacquesD at korbitec.com (Jacques du Preez) Date: Wed, 15 Jun 2011 14:42:28 +0000 Subject: [Ironruby-core] require_relative Message-ID: <4501DB5DEB929B44861FB53CA96785D56902EF@CPTISNMAIL02> Hi, I'm getting the following error trying to use the require_relative method in Ruby: "person.rb:3: undefined method `require_relative' for main:Object (NoMethodError)" Is require_relative not supposed to be standard in Ruby 1.9? I know I can use require, but I thought require_relative is now standard in 1.9... JACQUES DU PREEZ PROPCTRL DEVELOPER [Description: Description: C:\Users\martins\AppData\Roaming\Microsoft\Signatures\logo.jpg] Tel: +27 21 658 9700 Website: www.korbitec.com Fax: +27 21 658 9701 E-mail: jacquesd at korbitec.com Mobile +27 84 922 7284 Customer Service Centre: 0861 111 724 [Description: Description: C:\Users\martins\AppData\Roaming\Microsoft\Signatures\prop24.jpg][Description: Description: C:\Users\martins\AppData\Roaming\Microsoft\Signatures\propctrl.jpg][Description: Description: C:\Users\martins\AppData\Roaming\Microsoft\Signatures\ghostconvey.jpg][Description: Description: C:\Users\martins\AppData\Roaming\Microsoft\Signatures\windeed.jpg] This e-mail is subject to the Korbitec (Pty) Ltd e-mail disclaimer which can be found at www.korbitec.com/email_disclaimer.htm or or may be obtained by e-mailing csc at korbitec.com -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.jpg Type: image/jpeg Size: 3753 bytes Desc: image001.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.jpg Type: image/jpeg Size: 2892 bytes Desc: image002.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image003.jpg Type: image/jpeg Size: 2619 bytes Desc: image003.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image004.jpg Type: image/jpeg Size: 2444 bytes Desc: image004.jpg URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image005.jpg Type: image/jpeg Size: 2474 bytes Desc: image005.jpg URL: From jschementi at gmail.com Wed Jun 15 11:55:16 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Wed, 15 Jun 2011 11:55:16 -0400 Subject: [Ironruby-core] require_relative In-Reply-To: <4501DB5DEB929B44861FB53CA96785D56902EF@CPTISNMAIL02> References: <4501DB5DEB929B44861FB53CA96785D56902EF@CPTISNMAIL02> Message-ID: On Jun 15, 2011, at 10:42 AM, Jacques du Preez wrote: > Hi, > > I?m getting the following error trying to use the require_relative method in Ruby: > > ?person.rb:3: undefined method `require_relative' for main:Object (NoMethodError)? > > Is require_relative not supposed to be standard in Ruby 1.9? I know I can use require, but I thought require_relative is now standard in 1.9... IronRuby's Ruby-1.9 support is not complete, and require_relative has not been implemented yet in IronRuby. ~js -------------- next part -------------- An HTML attachment was scrubbed... URL: From thibaut.barrere at gmail.com Wed Jun 15 12:06:59 2011 From: thibaut.barrere at gmail.com (=?ISO-8859-1?Q?Thibaut_Barr=E8re?=) Date: Wed, 15 Jun 2011 18:06:59 +0200 Subject: [Ironruby-core] require_relative In-Reply-To: <4501DB5DEB929B44861FB53CA96785D56902EF@CPTISNMAIL02> References: <4501DB5DEB929B44861FB53CA96785D56902EF@CPTISNMAIL02> Message-ID: Hi Jacques, I?m getting the following error trying to use the require_relative method in Ruby: > person.rb:3: undefined method `require_relative' for main:Object > (NoMethodError)? > > Is require_relative not supposed to be standard in Ruby 1.9? I know I can > use require, but I thought require_relative is now standard in 1.9... > Which version of IronRuby are you using ? -- Thibaut > > > *JACQUES DU PREEZ*** > > *PROPCTRL DEVELOPER*** > > > > [image: Description: Description: > C:\Users\martins\AppData\Roaming\Microsoft\Signatures\logo.jpg] > > *Tel:* > > +27 21 658 9700 > > *Website*: www.korbitec.com > > *Fax:* > > +27 21 658 9701 > > *E-mail: *jacquesd at korbitec.com > > *Mobile* > > +27 84 922 7284 > > *Customer Service Centre:* 0861 111 724 > > [image: Description: Description: > C:\Users\martins\AppData\Roaming\Microsoft\Signatures\prop24.jpg][image: > Description: Description: > C:\Users\martins\AppData\Roaming\Microsoft\Signatures\propctrl.jpg][image: > Description: Description: > C:\Users\martins\AppData\Roaming\Microsoft\Signatures\ghostconvey.jpg][image: > Description: Description: > C:\Users\martins\AppData\Roaming\Microsoft\Signatures\windeed.jpg] > > *This e-mail is subject to the Korbitec (Pty) Ltd e-mail disclaimer which > can be found at www.korbitec.com/email_disclaimer.htm or > or may be obtained by e-mailing csc at korbitec.com*** > > > > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2619 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2892 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2444 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 3753 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: image/jpeg Size: 2474 bytes Desc: not available URL: From rob.s.brit at gmail.com Thu Jun 23 11:45:48 2011 From: rob.s.brit at gmail.com (Rob Britton) Date: Thu, 23 Jun 2011 11:45:48 -0400 Subject: [Ironruby-core] Creating RubySymbols in C# Message-ID: Hello, I'm attempting to write a method in C# that is called by IronRuby to speed up an existing script, and I call it like this: foo :limit => 5, :offset => 10 How would I go about accessing these objects from C#? I'm trying something like this: void foo(Hash options){ int limit = (int)options[new RubySymbol("limit")]; ... } However this doesn't work since RubySymbols constructor is private. How would I go about getting the objects within the hash? Thanks, Rob From jschementi at gmail.com Thu Jun 23 14:45:53 2011 From: jschementi at gmail.com (Jimmy Schementi) Date: Thu, 23 Jun 2011 14:45:53 -0400 Subject: [Ironruby-core] Creating RubySymbols in C# In-Reply-To: References: Message-ID: <7CA0ACB3-57D9-4FBA-9631-04F41ECFC27D@gmail.com> On Jun 23, 2011, at 11:45 AM, Rob Britton wrote: > I'm attempting to write a method in C# that is called by IronRuby to > speed up an existing script, and I call it like this: > > foo :limit => 5, :offset => 10 > > How would I go about accessing these objects from C#? I'm trying > something like this: > > void foo(Hash options){ > int limit = (int)options[new RubySymbol("limit")]; > ... > } > > However this doesn't work since RubySymbols constructor is private. > How would I go about getting the objects within the hash? Rob, it's best to avoid depending on IronRuby built-in types in your .NET API unless you absolutely need to, as well as always having your .NET API's arguments be interface types, so both Ruby and .NET can call into them. If you did this: // C# public class MyClass { public void Foo(IDictionary args) {} } You can still call it from Ruby: my_class.foo :limit => 5, :offset => 10 As for indexing, you can copy the provided Hash into a Dictionary to provide string-based indexing: void Foo(IDictionary args) { var dict = new Dictionary(); foreach (DictionaryEntry a in args) dict[a.Key.ToString()] = a.Value; var limit = dict["limit"]; var offset = dict["offset"]; // do your stuff } Another option (which I like more) is to write a Ruby wrapper around it to convert the keys to CLR strings: require 'MyClass' # load above assembly class MyClass # monkey-patch above .NET class alias :orig_foo :foo def foo(args) orig_foo args.inject({}){|i,(j,k)| i[j.to_clr_string] = k; i } end end Then you wouldn't have to do the conversion in C#: void Foo(IDictionary dict) { var limit = dict["limit"]; var offset = dict["offset"]; // do your stuff } I like the latter option best because you do what Ruby needs in Ruby; your .NET code assumes it's getting a CLR string rather than forcing it to be. However, it's not ideal as you have to copy the dictionary in both cases, but for an argument hash it's very unlikely to become an issue. You'll notice that if you a .NET method that accepts a string, you can pass it a Ruby symbol; we do the conversion between Ruby symbols and .NET strings. However, we don't do conversions between generic arguments, especially with a Ruby Hash, were they keys could be different types. But we could convert a Hash to a statically typed Dictionary if all they keys are the same type; if you feel strongly about this please open a bug. ~Jimmy -------------- next part -------------- An HTML attachment was scrubbed... URL: From rob.s.brit at gmail.com Mon Jun 27 09:40:30 2011 From: rob.s.brit at gmail.com (Rob Britton) Date: Mon, 27 Jun 2011 09:40:30 -0400 Subject: [Ironruby-core] Creating RubySymbols in C# In-Reply-To: <7CA0ACB3-57D9-4FBA-9631-04F41ECFC27D@gmail.com> References: <7CA0ACB3-57D9-4FBA-9631-04F41ECFC27D@gmail.com> Message-ID: Great, thanks! I don't feel strongly about it so I'll just put in a little helper function to my .NET project to convert a Hash to a Dictionary. The monkey-patching method might not work too well since there will be many functions that might use this pattern, and having to monkey-patch every single one of them might get annoying. On Thu, Jun 23, 2011 at 2:45 PM, Jimmy Schementi wrote: > On Jun 23, 2011, at 11:45 AM, Rob Britton wrote: > > I'm attempting to write a method in C# that is called by IronRuby to > speed up an existing script, and I call it like this: > > ?foo :limit => 5, :offset => 10 > > How would I go about accessing these objects from C#? I'm trying > something like this: > > void foo(Hash options){ > ?int limit = (int)options[new RubySymbol("limit")]; > ?... > } > > However this doesn't work since RubySymbols constructor is private. > How would I go about getting the objects within the hash? > > > Rob, it's best to avoid depending on IronRuby built-in types in your .NET > API unless you absolutely need to, as well as always having your .NET API's > arguments be interface types, so both Ruby and .NET can call into them. If > you did this: > ?? ?// C# > ?? ?public class MyClass { > ?? ? ? ?public void Foo(IDictionary args) {} > ?? ?} > You can still call it from Ruby: > ?? ?my_class.foo :limit => 5, :offset => 10 > As for indexing, you can copy the provided Hash into a Dictionary object> to provide string-based indexing: > ?? ?void?Foo(IDictionary?args) { > ?? ? ? ?var?dict =?new?Dictionary(); > ?? ? ? ?foreach?(DictionaryEntry?a?in?args)?dict[a.Key.ToString()] = > a.Value; > ?? ? ? ?var limit =?dict["limit"]; > ?? ? ? ?var offset = dict["offset"]; > ?? ? ? ?// do your stuff > ?? ?} > > > Another option (which I like more) is to write a Ruby wrapper around it to > convert the keys to CLR strings: > ?? ?require 'MyClass' # load above assembly > ?? ?class MyClass # monkey-patch above .NET class > ?? ? ? ?alias :orig_foo :foo > ?? ? ? ?def foo(args) > ?? ? ? ? ? ?orig_foo args.inject({}){|i,(j,k)| i[j.to_clr_string] = k; i } > ?? ? ? ?end > ?? ?end > Then you wouldn't have to do the conversion in C#: > ?? ?void?Foo(IDictionary?dict) { > ?? ? ? ?var limit =?dict["limit"]; > ?? ? ? ?var offset = dict["offset"]; > ?? ? ? ?// do your stuff > ?? ?} > I like the latter option best because you do what Ruby needs in Ruby; your > .NET code assumes it's getting a CLR string rather than forcing it to be. > However, it's not ideal as you have to copy the dictionary in both cases, > but for an argument hash it's very unlikely to become an issue. > You'll notice that if you a .NET method that accepts a string, you can pass > it a Ruby symbol; we do the conversion between Ruby symbols and .NET > strings. However, we don't do conversions between generic arguments, > especially with a Ruby Hash, were they keys could be different types. But we > could convert a Hash to a statically typed Dictionary if all they keys are > the same type; if you feel strongly about this please open a bug. > ~Jimmy > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > From llin at polypaths.com Thu Jun 30 15:58:34 2011 From: llin at polypaths.com (Lewis Lin) Date: Thu, 30 Jun 2011 15:58:34 -0400 Subject: [Ironruby-core] Access Top Level methods Message-ID: <4E0CD56A.5010203@polypaths.com> Hi, I am trying to access top level method from the class definition in IronRuby scripts. Example: def global_hi end class A def hi global_hi end end A.new.hi The script executed in ScriptEngine throws a NoSuchMethodError. I tried to ran the same code in iirb.exe It seems to behave the way I expected. But when I tried it in ir.exe, it throws the exception as well. I investigate a little more and found out irb(main):021:0> self.method(:global_hi) => # and in ir.exe as well as script engine >>> self.method(:xx) => #>)#xx> Is there anyway to make the script behave like the one in iirb.exe? Thanks, Lewis -------------- next part -------------- An HTML attachment was scrubbed... URL: From defeated2k4 at gmail.com Thu Jun 30 17:20:01 2011 From: defeated2k4 at gmail.com (Eddie Cianci) Date: Thu, 30 Jun 2011 17:20:01 -0400 Subject: [Ironruby-core] (no subject) Message-ID: -------------- next part -------------- An HTML attachment was scrubbed... URL: