Re: [MacRuby-devel] MacRuby not finding a method that Ruby is
Hi Laurent, I just tried running it under 0.5 and am still getting an error. I've narrowed the code down to the following: ### class A def initialize puts 'initialize' end def self.init define_method(:initialize) do |*params| super() end end end class B < A init end # Calling B.new without an argument, however, works. B.new nil ### HTH, Ed On Oct 8, 2009, at 12:21 AM, Laurent Sansonetti wrote: We fixed a few 32-bit issues in trunk so you may want to give it a try one more time. At least we are not maintaining 0.4 anymore, so it would be great if you could try your code with trunk and let us know if the bug is still there. Then we can try to reduce it and fix it :) Laurent On Oct 7, 2009, at 9:16 PM, Edward Hynes wrote: I'm still on a 32-bit machine, so can't try 0.5 yet :^( I did manage to find a workaround, however, by creating an alias for the 'initialize' method and then calling it instead of 'super' inside of the 'define_method' call. Ed On Oct 7, 2009, at 10:51 PM, Matt Aimonetti wrote: you might want to try your luck with 0.5 - Matt On Wed, Oct 7, 2009 at 7:37 PM, Edward Hynes wrote: Hi, I'm attempting to use the RParsec gem under MacRuby, but am getting a NoMethodError when it loads. I've create a test file that simply adds my local gem directory to the front of the library search path and then calls "require 'rparsec'". This file runs fine under Ruby 1.9, but produces the following error when called from MacRuby 0.4. /Users/ehynes/Test/Gems/rparsec/parser.rb:32:in `block in init': super: no superclass method `initialize:' for RParsec::ValueParser:RParsec::ValueParser (NoMethodError) from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `new' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:3:in `(required)>' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `require' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `block in (required)>' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `each' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `>' from AbcParser.rb:2:in `require' from AbcParser.rb:2:in `' The method with the error in the Parser class is: def self.init(*vars) parser_checker = {} vars.each_with_index do |var, i| name = var.to_s parser_checker[i] = var if name.include?('parser') && ! name.include?('parsers') end define_method(:initialize) do |*params| ---> super() # <--- line 32 vars.each_with_index do |var, i| param = params[i] if parser_checker.include? i TypeChecker.check_arg_type Parser, param, self, i end instance_variable_set("@"+var.to_s, param) end end end Any ideas as to why Ruby can call super in the above method, but MacRuby can't? Is there a fix or workaround that I could use? An alternate parser? Thanks, Ed P.S. I did have to change one line in the RParsec parser.rb file to get it to run under Ruby 1.9, replacing a ':' with a 'then' in a case statement. $ diff parser_original.rb parser.rb 881c881 < case c when String: c[0] else c end --- > case c when String then c[0] else c end # ':' replaced with 'then' ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel -- Edward Hynes Dharma Gaia LLC "Software with the Earth in Mind" http://dharmagaia.com ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel -- Edward Hynes Dharma Gaia LLC "Software with the Earth in Mind" http://dharmagaia.com ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] MacRuby not finding a method that Ruby is
I'm still on a 32-bit machine, so can't try 0.5 yet :^( I did manage to find a workaround, however, by creating an alias for the 'initialize' method and then calling it instead of 'super' inside of the 'define_method' call. Ed On Oct 7, 2009, at 10:51 PM, Matt Aimonetti wrote: you might want to try your luck with 0.5 - Matt On Wed, Oct 7, 2009 at 7:37 PM, Edward Hynes wrote: Hi, I'm attempting to use the RParsec gem under MacRuby, but am getting a NoMethodError when it loads. I've create a test file that simply adds my local gem directory to the front of the library search path and then calls "require 'rparsec'". This file runs fine under Ruby 1.9, but produces the following error when called from MacRuby 0.4. /Users/ehynes/Test/Gems/rparsec/parser.rb:32:in `block in init': super: no superclass method `initialize:' for RParsec::ValueParser:RParsec::ValueParser (NoMethodError) from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `new' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:3:in `(required)>' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `require' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `block in (required)>' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `each' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `' from AbcParser.rb:2:in `require' from AbcParser.rb:2:in `' The method with the error in the Parser class is: def self.init(*vars) parser_checker = {} vars.each_with_index do |var, i| name = var.to_s parser_checker[i] = var if name.include?('parser') && ! name.include?('parsers') end define_method(:initialize) do |*params| ---> super() # <--- line 32 vars.each_with_index do |var, i| param = params[i] if parser_checker.include? i TypeChecker.check_arg_type Parser, param, self, i end instance_variable_set("@"+var.to_s, param) end end end Any ideas as to why Ruby can call super in the above method, but MacRuby can't? Is there a fix or workaround that I could use? An alternate parser? Thanks, Ed P.S. I did have to change one line in the RParsec parser.rb file to get it to run under Ruby 1.9, replacing a ':' with a 'then' in a case statement. $ diff parser_original.rb parser.rb 881c881 < case c when String: c[0] else c end --- > case c when String then c[0] else c end # ':' replaced with 'then' ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel -- Edward Hynes Dharma Gaia LLC "Software with the Earth in Mind" http://dharmagaia.com ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] MacRuby not finding a method that Ruby is
Hi, I'm attempting to use the RParsec gem under MacRuby, but am getting a NoMethodError when it loads. I've create a test file that simply adds my local gem directory to the front of the library search path and then calls "require 'rparsec'". This file runs fine under Ruby 1.9, but produces the following error when called from MacRuby 0.4. /Users/ehynes/Test/Gems/rparsec/parser.rb:32:in `block in init': super: no superclass method `initialize:' for RParsec::ValueParser:RParsec::ValueParser (NoMethodError) from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `new' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:621:in `' from /Users/ehynes/Test/Gems/rparsec/parsers.rb:3:in `' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `require' from /Users/ehynes/Test/Gems/rparsec.rb:3:in `block in (required)>' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `each' from /Users/ehynes/Test/Gems/rparsec.rb:2:in `' from AbcParser.rb:2:in `require' from AbcParser.rb:2:in `' The method with the error in the Parser class is: def self.init(*vars) parser_checker = {} vars.each_with_index do |var, i| name = var.to_s parser_checker[i] = var if name.include?('parser') && ! name.include?('parsers') end define_method(:initialize) do |*params| ---> super() # <--- line 32 vars.each_with_index do |var, i| param = params[i] if parser_checker.include? i TypeChecker.check_arg_type Parser, param, self, i end instance_variable_set("@"+var.to_s, param) end end end Any ideas as to why Ruby can call super in the above method, but MacRuby can't? Is there a fix or workaround that I could use? An alternate parser? Thanks, Ed P.S. I did have to change one line in the RParsec parser.rb file to get it to run under Ruby 1.9, replacing a ':' with a 'then' in a case statement. $ diff parser_original.rb parser.rb 881c881 < case c when String: c[0] else c end --- > case c when String then c[0] else c end # ':' replaced with 'then' ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Initializing Structs with Bytes?
Hi, I'm calling a function, via bridesupport, that returns a void pointer to a c structure. I'd like to instantiate a MacRuby structure using that void pointer. Is there a way to do this? Thanks, Ed ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] BridgeSupport and Parameter Errors
I'm trying to re-implement the PlaySoftMIDI example from the Xcode installation in MacRuby, but am getting parameter errors. Could some kind soul point me in the right direction? Below is a small example that ends with a parameter error. The call to NewAUGraph appears to work, returning a zero, but the call to AUGraphAddNode returns -50. framework 'AudioToolbox' framework 'AudioUnit' load_bridge_support_file 'bridgesupport/Application.bridgesupport' load_bridge_support_file 'bridgesupport/AudioToolbox.bridgesupport' load_bridge_support_file 'bridgesupport/AudioUnit.bridgesupport' outGraph = Pointer.new_with_type '^{OpaqueAUGraph}' result = NewAUGraph outGraph # returns 0 puts result cd = ComponentDescription.new cd.componentManufacturer = KAudioUnitManufacturer_Apple cd.componentType = KAudioUnitType_MusicDevice cd.componentSubType = KAudioUnitSubType_DLSSynth cd_ptr = Pointer.new_with_type '{ComponentDescription=I}' cd_ptr.assign cd synthNode = Pointer.new_with_type 'i' result = AUGraphAddNode outGraph[0], cd_ptr, synthNode # returns -50 puts result I generated the bridge support files with gen_bridge_metadata -f AudioToolbox -o AudioToolbox.bridgesupport gen_bridge_metadata -f AudioUnit -o AudioUnit.bridgesupport The Application.bridgesupport file contains struct and cftype definitions for ComponentDescription. They were generated using a header file since I couldn't figure out how to generate them from the CarbonCore framework directly. Any help would be appreciated. Thanks, Ed ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Xcode Executable Arguments
Hi, I'm working on localization for a MacRuby app and would like to be able to set the language in the Executable Info's Arguments tab in Xcode, but the arguments are being gobbled up by MacRuby. Is there a way to escape or quote executable arguments so that they are passed through to the application? I'm setting the arguments using the defaults command for now, but it would prefer doing so within Xcode if possible. Thanks, Ed -- Edward Hynes Dharma Gaia LLC "Software with the Earth in Mind" http://dharmagaia.com ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] How to retrieve an observer's context?
Hi Laurent, Thanks for the help. Did you mean to set the context ivar on the observer or on the subject? Wouldn't setting it on the observer result in the last registration 'winning' if the observer is watching more than one subject? Ed On Apr 20, 2009, at 4:28 PM, Laurent Sansonetti wrote: Hi Edward, Context arguments in Objective-C are generally void pointers, which makes them hard to use in Ruby. Also, since we run in Objective-C GC mode, objects could potentially be collected since contexts do not set up AFAIK write barriers. I would recommend to set up an instance variable on your observer instead (and pass nil as the context). observer.instance_variable_set(:@context, your_context) And later in your observer method, retrieve the ivar. Laurent ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] How to retrieve an observer's context?
I'd like to use contexts when registering some observers, but have been unable to retrieve them, getting a "can't convert C/Objective-C value `0x2822731' of type `v' to Ruby object" instead. The following code, for example, will trigger the error class Subject attr_accessor :abc end class Observer def observeValueForKeyPath keyPath, ofObject:object, change:change, context:context context[0] end end subject = Subject.new observer = Observer.new subject.addObserver observer, forKeyPath:'abc', options:0, context:'a context' subject.setAbc 'some value' Is there a way to retrieve an observation context? Or is there an alternative way for observers to distinguish among multiple registrations for a given object/keyPath? Thanks, Ed ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Re: [MacRuby-devel] Accessing Obj-C InstVars from Ruby
Accessors, it's s obvious (after you all pointed the way ;^) Thanks, Ed ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
[MacRuby-devel] Accessing Obj-C InstVars from Ruby
Is there a way to access instance variables defined in an Objective-C class from a Ruby extension? I'm porting some of Apple's example code to MacRuby as a learning experience and would like to do so incrementally. Porting the code one class at a time works fine, but for some of the larger classes I'd like to port them a few methods at a time. Here's an example of what's happening --- Example.h --- @interface Example : NSObject { NSString *instVarA; NSString *instVarB; } - (NSString *)methodA; @end --- Example.m --- #import "Example.h" @implementation Example - (id)init { if (self = [super init]) { instVarA = @"instVarA"; instVarB = @"instVarB"; } return self; } - (NSString *)methodA { return instVarA; } @end --- Example.rb --- class Example def methodB @instVarB end end Then at runtime, when I execute the following... example = Example.alloc.init puts example.methodA.inspect puts example.methodB.inspect .. I get "instVarA" nil How do I access InsVarB from Ruby? Thanks, Ed ___ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel