[MacRuby] #720: dynamically defined method called by menu items bug
#720: dynamically defined method called by menu items bug -------------------------------------+-------------------------------------- Reporter: mattaimonetti@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Here is a reduction of the bug encountered when a menu item calls a dynamically defined method. Run the following code and click on one of the two first menu items to reproduce the bug. {{{ framework 'AppKit' app = NSApplication.sharedApplication class ItemDelegate def define_actions(actions) actions.each do |command| self.class.send(:define_method, command) do |sender| puts command end end end def quit(sender) exit end end @menu = NSMenu.alloc.init actions = ['test', 'test2'] menu_delegate = ItemDelegate.new menu_delegate.define_actions(actions) actions.each do |action| item = @menu.addItemWithTitle(action, action: action, keyEquivalent: "") item.target = menu_delegate end item = @menu.addItemWithTitle("Quit", action: 'quit:', keyEquivalent: "q") item.toolTip = "Click to close this App" item.target = menu_delegate bar = NSStatusBar.systemStatusBar.statusItemWithLength(NSSquareStatusItemLength) bar.title = "test" bar.menu = @menu bar.highlightMode = true app.run }}} http://gist.github.com/403462 {{{ 2010-05-16 23:15:19.037 macruby[29001:903] HIToolbox: ignoring exception '/Users/mattetti/bug.rb:1:in `<main>': wrong number of arguments (5393856 for 1) (ArgumentError) ' that raised inside Carbon event dispatch ( 0 CoreFoundation 0x00007fff86dbad24 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x00007fff851440f3 objc_exception_throw + 45 2 libmacruby.dylib 0x0000000100160a4f rb_vm_raise + 335 3 libmacruby.dylib 0x0000000100045cf9 rb_exc_raise + 9 4 libmacruby.dylib 0x0000000100044234 rb_raise + 308 5 libmacruby.dylib 0x0000000100148cf8 rb_vm_block_eval2 + 2104 6 ??? 0x0000000101101380 0x0 + 4312798080 7 AppKit 0x00007fff8324d8ea -[NSApplication sendAction:to:from:] + 95 8 AppKit 0x00007fff83271e5a -[NSMenuItem _corePerformAction] + 365 9 AppKit 0x00007fff83271bc4 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 121 10 AppKit 0x00007fff834f593d -[NSMenu _internalPerformActionForItemAtIndex:] + 35 11 AppKit 0x00007fff833a7729 -[NSCarbonMenuImpl _carbonCommandProcessEvent:handlerCallRef:] + 136 12 AppKit 0x00007fff832543b0 NSSLMMenuEventHandler + 321 13 HIToolbox 0x00007fff85664b57 _ZL23DispatchEventToHandlersP14EventTargetRecP14OpaqueEventRefP14HandlerCallRec + 1002 14 HIToolbox 0x00007fff856640a6 _ZL30SendEventToEventTargetInternalP14OpaqueEventRefP20OpaqueEventTargetRefP14HandlerCallRec + 395 15 HIToolbox 0x00007fff85681d85 SendEventToEventTarget + 45 16 HIToolbox 0x00007fff856b0e61 _ZL18SendHICommandEventjPK9HICommandjjhPKvP20OpaqueEventTargetRefS5_PP14OpaqueEventRef + 387 17 HIToolbox 0x00007fff856ddbf6 SendMenuCommandWithContextAndModifiers + 56 18 HIToolbox 0x00007fff856ddbae SendMenuItemSelectedEvent + 101 19 HIToolbox 0x00007fff856ddabe _ZL19FinishMenuSelectionP13SelectionDataP10MenuResultS2_ + 150 20 HIToolbox 0x00007fff857e6acb _ZL19PopUpMenuSelectCoreP8MenuData5PointdS1_tjPK4RecttjS4_S4_PK10__CFStringPP13OpaqueMenuRefPt + 1618 21 HIToolbox 0x00007fff857e6e24 _HandlePopUpMenuSelection7 + 665 22 AppKit 0x00007fff833a46db _NSSLMPopUpCarbonMenu3 + 3720 23 AppKit 0x00007fff835d41b5 -[NSStatusBarButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 162 24 AppKit 0x00007fff832d7c59 -[NSControl mouseDown:] + 624 25 AppKit 0x00007fff831f1f1b -[NSWindow sendEvent:] + 5409 26 AppKit 0x00007fff835d4f54 -[NSStatusBarWindow sendEvent:] + 68 27 AppKit 0x00007fff83127662 -[NSApplication sendEvent:] + 4719 28 AppKit 0x00007fff830be0aa -[NSApplication run] + 474 29 ??? 0x0000000101101ac7 0x0 + 4312799943 30 libmacruby.dylib 0x000000010014b5c0 rb_vm_dispatch + 3184 31 ??? 0x0000000101100834 0x0 + 4312795188 32 libmacruby.dylib 0x000000010015f35f rb_vm_run + 351 33 libmacruby.dylib 0x0000000100045f59 ruby_run_node + 73 34 macruby 0x0000000100000d28 main + 152 35 macruby 0x0000000100000c88 start + 52 ) }}} (tested with MacRuby 0.6 final) -- Ticket URL: <http://www.macruby.org/trac/ticket/720> MacRuby <http://macruby.org/>
#720: dynamically defined method called by menu items bug -------------------------------------+-------------------------------------- Reporter: mattaimonetti@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by mattaimonetti@…): An even better reduction: {{{ self.class.send(:define_method, 'test') do |sender| puts 'test' end self.performSelector('test:', withObject:self) }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/720#comment:1> MacRuby <http://macruby.org/>
I have a binding of an user interface element to my controller (Controller.self.test): The setTest does work, but the 'test =' does not. class Controller < NSWindowController attr_accessor :test def works setTest true end def doesnotwork test = true end end Is this a bug? - Bernd
Hi ! What exactly is not working? You said you have "Controller.self.test", what do you mean by that? Both setX and X= work for me, here is what I get: $> cat t.rb class A attr_accessor :someAttr end a = A.new a.setSomeAttr "set via #setSomeAttr" p a.someAttr a.someAttr = "set via #someAttr=" p a.someAttr $> macruby t.rb "set via #setSomeAttr" "set via #someAttr=" -- Thibault Martin-Lagardette On May 17, 2010, at 00:47, B. Ohr wrote:
I have a binding of an user interface element to my controller (Controller.self.test): The setTest does work, but the 'test =' does not.
class Controller < NSWindowController attr_accessor :test
def works setTest true end
def doesnotwork test = true end
end
Is this a bug?
- Bernd _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Hi! Oh sorry, my first message was a little bit too short. In the IB I created a button and on the bindings pane I connected the hidden property to Controller, the ‚Model Key Path‘ is set to 'Controller.self.test‘. Now when I am calling ‚work‘ the button gets hidden, but with ‚doesnotwork‘ the button remains visible. There seems to be no notification. - Bernd Am 17.05.2010 um 10:00 schrieb Thibault Martin-Lagardette:
Hi !
What exactly is not working? You said you have "Controller.self.test", what do you mean by that? Both setX and X= work for me, here is what I get:
$> cat t.rb class A attr_accessor :someAttr end
a = A.new a.setSomeAttr "set via #setSomeAttr" p a.someAttr a.someAttr = "set via #someAttr=" p a.someAttr
$> macruby t.rb "set via #setSomeAttr" "set via #someAttr="
-- Thibault Martin-Lagardette
On May 17, 2010, at 00:47, B. Ohr wrote:
I have a binding of an user interface element to my controller (Controller.self.test): The setTest does work, but the 'test =' does not.
class Controller < NSWindowController attr_accessor :test
def works setTest true end
def doesnotwork test = true end
end
Is this a bug?
- Bernd _______________________________________________ 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
class Controller < NSWindowController attr_accessor :test def works setTest true end def doesnotwork test = true end end
"test = true" should be "self.test = true" "test = true" just creates a local variable named test. It's a very common mistake in Ruby.
Ooops, shame on me, you are right. Now it is working…. Am 17.05.2010 um 10:20 schrieb Vincent Isambart:
class Controller < NSWindowController attr_accessor :test def works setTest true end def doesnotwork test = true end end
"test = true" should be "self.test = true" "test = true" just creates a local variable named test. It's a very common mistake in Ruby. _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
participants (4)
-
B. Ohr
-
MacRuby
-
Thibault Martin-Lagardette
-
Vincent Isambart