Objc ffi: implement `windowWillClose:`

The code is like:

(define-objc-class MyView NSView
  ()
  (- _void (windowWillClose: [(_cpointer 'NSNotification) notification])
     (tell app terminate: #:type _id self)))

the corresponding code in Objective-C correct handle signal like Ctrl+C, but racket version cannot work same.

Full code:

1 Like

I'm not sure I follow, but I think you're seeing that Racket installs a SIGINT handler to convert Ctl-C into a Racket exn:break exception. On macOS, you could remove that signal handler with

((get-ffi-obj 'signal #f (_fun _int _intptr -> _void)) 2 0)

and then Ctl-C terminates "simple-view.rkt".

But it's not about windowWillClose: in that case; the default Ctl-C treatment exits immediately without calling object methods. An immediate exit on Ctl-C also seems to happen when I run "main.m", so I may be missing something about your setup.

1 Like

Interesting! so more like racket does something and stop me, not objc doing something here. But I still have a problem that

(- _void (drawRect: [_NSRect rect])
  ...)

didn't work. Maybe just keep tracking in this topic? Since they're about implement objc method

Your drawing code has (in-range (* 2 pi) (/ (* 2 pi) n)) where you meant (in-range 0 (* 2 pi) (/ (* 2 pi) n)). Also, you'll need to specify #:type _NSPoint for each argument to strokeLineFromPoint:toPoint:.

1 Like

oops, another stupid error made by myself. Thanks a lot! You save my day.