[MacRuby-devel] [MacRuby] #529: Using a Proc as a ‘callback function’
MacRuby
ruby-noreply at macosforge.org
Wed Dec 30 03:55:32 PST 2009
#529: Using a Proc as a ‘callback function’
-------------------------------------+--------------------------------------
Reporter: eloy.de.enige@… | Owner: lsansonetti@…
Type: defect | Status: new
Priority: blocker | Milestone:
Component: MacRuby | Keywords:
-------------------------------------+--------------------------------------
Some Cocoa methods, or C functions, take pointers to functions which can
be used as callbacks. For instance, FSEventStreamCreate:
http://bit.ly/8p70Yw.
RubyCocoa, in conjunction with BridgeSupport, supported this by allowing
the user to give a proc that would be used as the callback. MacRuby should
support this too.
Here's a spec example:
{{{
describe "BridgeSupport" do
it "bridges a proc to be used where a pointer to a callback function is
required" do
array = [5, 3, 2, 4, 1]
proc = Proc.new do |x, y, context_pointer|
context = context_pointer[0].chr + context_pointer[1].chr +
context_pointer[2].chr
x <=> y if context == 'foo'
end
array.sortUsingFunction(proc, context: 'bar')
array.should == [5, 3, 2, 4, 1]
array.sortUsingFunction(proc, context: 'foo')
array.should == [1, 2, 3, 4, 5]
end
end
}}}
Don't know if this is feasible, but it would be great if the arguments
given to the proc, like the context argument, were no Pointer objects, but
the object they actually point to:
{{{
describe "BridgeSupport" do
it "bridges a proc to be used where a pointer to a callback function is
required" do
array = [5, 3, 2, 4, 1]
proc = Proc.new do |x, y, context|
x <=> y if context == 'foo'
end
array.sortUsingFunction(proc, context: 'bar')
array.should == [5, 3, 2, 4, 1]
array.sortUsingFunction(proc, context: 'foo')
array.should == [1, 2, 3, 4, 5]
end
end
}}}
--
Ticket URL: <http://www.macruby.org/trac/ticket/529>
MacRuby <http://macruby.org/>
More information about the MacRuby-devel
mailing list