summaryrefslogtreecommitdiff
path: root/Lisp/init.lisp
blob: 91f24e98f0d81822359bdf77dd3422543984ddf0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
;;;; Objective-CL, an Objective-C bridge for Common Lisp.
;;;; Copyright (C) 2007  Matthias Andreas Benkard.
;;;;
;;;; This program is free software: you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public License
;;;; as published by the Free Software Foundation, either version 3 of
;;;; the License, or (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful, but
;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this program.  If not, see
;;;; <http://www.gnu.org/licenses/>.

(in-package #:mulk.objective-cl)

(initialise-runtime)

(eval-when (:load-toplevel)
  (unless (boundp '+nil+)
    ;; As nil is never deallocated, we can safely use MAKE-INSTANCE
    ;; here.
    (defconstant +nil+
      (make-instance 'id :pointer (objcl-get-nil))))
  (unless (boundp '+yes+)
    (defconstant +yes+ (objcl-get-yes)))
  (unless (boundp '+no+)
    (defconstant +no+ (objcl-get-no)))
  (unless (boundp '+runtime-type+)
    (defconstant +runtime-type+ (runtime-type)))
  (pushnew (case (runtime-type)
             ((:gnu) 'objcl-features:gnu-runtime)
             ((:next) 'objcl-features:next-runtime))
           *features*))


(setf (documentation '+nil+ 'variable)
      "The Objective-C constant value `nil`.

## Value Type:

an **object** of type __id__.


## Description:

__+nil+__ is the constant corresponding to the Objective-C `nil` value.

__+nil+__ is not a value that any method invocation should return.
Whenever `nil` is returned by an Objective-C invocation, It is the job
of Objective-CL to convert it to __nil__.  Similarly, __null__ arguments
are converted to `nil` automatically.  Still, there may be occasions in
which it is useful to have `nil` as an __id__ instance.  Therefore, it
is provided here.

Note that, in the general case, `nil` is not necessarily equal to
`NULL`.")


(setf (documentation '+yes+ 'variable)
      "The Objective-C boolean value `YES`.

## Value Type:

a **number**.


## Description:

__+yes+__ is the constant corresponding to the Objective-C `YES` value.

As there is no way to distinguish methods that return booleans from
those that return numbers in the Objective-C runtime, all invocations
that ought to return booleans will actually return one of two
compile-time Objective-C constants: either `YES` or `NO`.  Lisp code
using Objective-CL needs to be aware of this and test return values
accordingly.  For this to be possible, two **constant**s are defined on
the Lisp side, analogously to Objective-C.  These are called __+yes+__
and __+no+__.


## Examples:

    (invoke (find-class 'ns-string)
            :is-subclass-of-class (find-class 'ns-object))
     ;=> #.YES

    (invoke (find-class 'ns-object)
            :is-subclass-of-class (find-class 'ns-object))
     ;=> #.YES

    (invoke (find-class 'ns-object)
            :is-subclass-of-class (find-class 'ns-string))
     ;=> #.NO


## See Also:

  __+no+__")


(setf (documentation '+no+ 'variable)
      "The Objective-C boolean value `NO`.

## Value Type:

a **number**.


## Description:

__+no+__ is the constant corresponding to the Objective-C `NO` value.

As there is no way to distinguish methods that return booleans from
those that return numbers in the Objective-C runtime, all invocations
that ought to return booleans will actually return one of two
compile-time Objective-C constants: either `YES` or `NO`.  Lisp code
using Objective-CL needs to be aware of this and test return values
accordingly.  For this to be possible, two **constant**s are defined on
the Lisp side, analogously to Objective-C.  These are called __+yes+__
and __+no+__.


## Examples:

    (invoke (find-class 'ns-string)
            :is-subclass-of-class (find-class 'ns-object))
     ;=> #.YES

    (invoke (find-class 'ns-object)
            :is-subclass-of-class (find-class 'ns-object))
     ;=> #.YES

    (invoke (find-class 'ns-object)
            :is-subclass-of-class (find-class 'ns-string))
     ;=> #.NO


## See Also:

  __+yes+__")