LoginSignup
7
7

More than 5 years have passed since last update.

Clozure CLからObjective-Cクラスを利用する

Posted at

さすがMCLの流れを汲むだけあって、割と簡単にObjective-CおよびCocoaフレームワークと連携できたのでメモ。

詳細は以下を参照。

サンプル

通知センターに通知を出すサンプル。
こちらのObjective-Cのサンプルを参考にさせてもらった。http://d.hatena.ne.jp/zariganitosh/20120913/user_notification_hello_world

(require "COCOA")

(let ((notification (#/init (#/alloc ns:ns-user-notification))))
  (#/setTitle: notification #@"Hello World")
  (#/setInformativeText: notification #@"This is information text.")
  (ccl::lisp-string-from-nsstring (#/title notification))
  (ccl::lisp-string-from-nsstring (#/informativeText notification))
  (#/deliverNotification: (#/defaultUserNotificationCenter ns:ns-user-notification-center)
                          notification)
  )

リーダマクロ #/

ドキュメントだと ccl::send でメッセージパッシングを行っているが、そっちのやり方はもうDeprecatedだとreplで警告がでたので、基本的にリーダマクロ #/ を使うほうがいいだろう。記述順序的にやや読みづらいが、記述量は結構減らせる。

ccl::send だと (ccl::send *n* :init-with-int 42) のようなlisp-likeに変換されたセレクタ名を指定するが、 #/ だと (#/initWithInt: *n* 42) のようにObjective-Cでのセレクタ名そのままになる。もちろんセミコロンも含む。

詳細は以下を参照。
http://ccl.clozure.com/ccl-documentation.html#rm_sharpsign-slash

その他

CCLのGCでメモリ回収されるのか、独自のクラスやフレームワークのバインディング作成はどうやるのか、あたりをもうちょっと調べる

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7