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不得不說這個。
謝謝!