3
我已经实现了选择器alertDidEnd:returnCode:contextInfo:
。最后一个参数contextInfo是一个空指针。在调用方法之前,我将指针放在一起,如下所示。为什么我的Macruby指针不能作为void指针传递?
# in windowShouldClose
p = Pointer.new(:boolean)
p.assign(true)
然后我调用该方法,它的体内有以下几点:
# in alertDidEnd
puts p[0] # => a number like 245
puts p.cast!('B')[0] # => false (rather than true)
我在做什么错?这是因为调用方法(windowShouldClose)在它自己的线程中完成之前,这个选择器有机会(只是猜测)?
或者我应该创建指针作为对象指针?
# make a pointer to an object and assign to it the instance of TrueClass
p = Pointer.new(:id)
p.assign(true)
我读过什么O'reilly Macruby Book不得不说这个。
谢谢!