cocoa: hack around NSApplication's handling of command-line arguments

This commit is contained in:
Matthew Flatt 2010-12-02 11:52:42 -07:00
parent 778f0c9fc4
commit 3479f5fb92
2 changed files with 23 additions and 2 deletions

View File

@ -33,7 +33,9 @@
(define _BOOL (make-ctype _byte
(lambda (v) (if v 1 0))
(lambda (v) (not (eq? v 0)))))
(define _IMP (_fun _id _id -> _id))
(define _Method (_cpointer/null 'Method))
(define _IMP (_fun _id _SEL -> _id))
(define-cstruct _objc_super ([receiver _id][class _Class]))
@ -864,3 +866,10 @@
(define (objc-is-a? v c)
(ptr-equal? (object-get-class v) c))
;; --------------------------------------------------
(define-objc class_getInstanceMethod (_fun _Class _SEL -> _Method))
(define-objc method_setImplementation (_fun _Method _IMP -> _IMP))

View File

@ -29,9 +29,21 @@
queue-event
yield)
(import-class NSApplication NSAutoreleasePool NSColor)
(import-class NSApplication NSAutoreleasePool NSColor NSProcessInfo NSArray)
(import-protocol NSApplicationDelegate)
;; Extreme hackery to hide original arguments from
;; NSApplication, because NSApplication wants to turn
;; the arguments into `application:openFile:' calls.
;; To hide the arguments, we replace the implementation
;; of `arguments' in the NSProcessInfo object.
(define (hack-argument-replacement self method)
(tell NSArray
arrayWithObjects: #:type (_vector i _NSString) (vector (path->string (find-system-path 'exec-file)))
count: #:type _NSUInteger 1))
(let ([m (class_getInstanceMethod NSProcessInfo (selector arguments))])
(void (method_setImplementation m hack-argument-replacement)))
(define app (tell NSApplication sharedApplication))
(define-objc-class MyApplicationDelegate NSObject #:protocols (NSApplicationDelegate)