1 <!-- -*- DocBook -*- -->
5 <title>Declarations</title>
9 <title>Overview</title>
10 <para>Declarations are used to give the compiler optimizing
11 information about foreign types. Currently, only &cmucl;
12 supports declarations. On &acl; and &lw;, these expressions
13 declare the type generically as &t;
18 <refentry id="def-type">
20 <refname>def-type</refname>
21 <refpurpose>Defines a Common Lisp type.
23 <refclass>Macro</refclass>
28 <function>def-type</function> <replaceable>name type</replaceable>
32 <title>Arguments and Values</title>
35 <term><parameter>name</parameter></term>
37 <para>A symbol naming the type</para>
41 <term><parameter>type</parameter></term>
43 <para>A form that is evaluated that specifies the &uffi; type.
50 <title>Description</title>
51 <para>Defines a Common Lisp type based on a &uffi; type.
55 <title>Examples</title>
57 (def-type char-ptr '(* :char))
60 (declare (type char-ptr ptr))
65 <title>Side Effects</title>
66 <para>Defines a new &cl; type.</para>
69 <title>Affected by</title>
73 <title>Exceptional Situations</title>
81 <title>Primitive Types</title>
83 <title>Overview</title>
85 Primitive types have a single value, these include
86 characters, numbers, and pointers. They are all symbols in
91 <para><constant>:char</constant> - Signed 8-bits. A
92 dereferenced :char pointer returns an character.</para>
96 <para><constant>:unsigned-char</constant> - Unsigned 8-bits. A dereferenced :unsigned-char
97 pointer returns an character.</para>
101 <para><constant>:byte</constant> - Unsigned 8-bits. A
102 dereferenced :byte pointer returns an integer.</para>
105 <para><constant>:short</constant> - Signed 16-bits.</para>
108 <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
111 <para><constant>:int</constant> - Signed 32-bits.</para>
114 <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
117 <para><constant>:long</constant> - Signed 32-bits.</para>
120 <para><constant>:unsigned-long</constant> - Unsigned 32-bits.</para>
123 <para><constant>:float</constant> - 32-bit floating point.</para>
126 <para><constant>:double</constant> - 64-bit floating point.</para>
129 <para><constant>:cstring</constant> -
130 A &null; terminated string used for passing and returning characters strings with a &c; function.
134 <para><constant>:void</constant> -
135 The absence of a value. Used to indicate that a function does not return a value.</para>
138 <para><constant>:pointer-void</constant> -
139 Points to a generic object.</para>
142 <para><constant>*</constant> - Used to declare a pointer to an object</para>
147 <refentry id="def-constant">
149 <refname>def-constant</refname>
150 <refpurpose>Binds a symbol to a constant.
152 <refclass>Macro</refclass>
155 <title>Syntax</title>
157 <function>def-constant</function> <replaceable>name value &key export</replaceable>
161 <title>Arguments and Values</title>
164 <term><parameter>name</parameter></term>
166 <para>A symbol that will be bound to the value.
171 <term><parameter>value</parameter></term>
173 <para>An evaluated form that is bound the the name.
178 <term><parameter>export</parameter></term>
180 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
186 <title>Description</title>
188 This is a thin wrapper around
189 <function>defconstant</function>. It evaluates at
190 compile-time and optionally exports the symbol from the package.
194 <title>Examples</title>
196 (def-constant pi2 (* 2 pi))
197 (def-constant exported-pi2 (* 2 pi) :export t)
201 <title>Side Effects</title>
202 <para>Creates a new special variable..</para>
205 <title>Affected by</title>
209 <title>Exceptional Situations</title>
214 <refentry id="def-foreign-type">
216 <refname>def-foreign-type</refname>
217 <refpurpose>Defines a new foreign type.
219 <refclass>Macro</refclass>
222 <title>Syntax</title>
224 <function>def-foreign-type</function> <replaceable>name type</replaceable>
228 <title>Arguments and Values</title>
231 <term><parameter>name</parameter></term>
233 <para>A symbol naming the new foreign type.
238 <term><parameter>value</parameter></term>
240 <para>A form that is not evaluated that defines the new
248 <title>Description</title>
249 <para>Defines a new foreign type.
253 <title>Examples</title>
255 (def-foreign-type my-generic-pointer :pointer-void)
256 (def-foreign-type a-double-float :double-float)
257 (def-foreign-type char-ptr (* :char))
261 <title>Side Effects</title>
262 <para>Defines a new foreign type.
266 <title>Affected by</title>
270 <title>Exceptional Situations</title>
275 <refentry id="null-char-p">
277 <refname>null-char-p</refname>
278 <refpurpose>Tests a character for &null; value.
280 <refclass>Macro</refclass>
283 <title>Syntax</title>
285 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
289 <title>Arguments and Values</title>
292 <term><parameter>char</parameter></term>
294 <para>A character or integer.
299 <term><parameter>is-null</parameter></term>
301 <para>A boolean flag indicating if char is a &null; value.
308 <title>Description</title>
310 A predicate testing if a character or integer is &null;. This
311 abstracts the difference in implementations where some return a
312 <computeroutput>character</computeroutput> and some return a
313 <computeroutput>integer</computeroutput> whence dereferencing a
314 <computeroutput>C</computeroutput> character pointer.
318 <title>Examples</title>
321 (let ((fs (convert-to-foreign-string "ab")))
322 (values (null-char-p (deref-array fs 'ca 0))
323 (null-char-p (deref-array fs 'ca 2))))
329 <title>Side Effects</title>
334 <title>Affected by</title>
338 <title>Exceptional Situations</title>
345 <title>Aggregate Types</title>
347 <title>Overview</title>
349 Aggregate types are comprised of one or more primitive types.
353 <refentry id="def-enum">
355 <refname>def-enum</refname>
356 <refpurpose>Defines a &c; enumeration.
358 <refclass>Macro</refclass>
361 <title>Syntax</title>
363 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
367 <title>Arguments and Values</title>
370 <term><parameter>name</parameter></term>
372 <para>A symbol that names the enumeration.
377 <term><parameter>fields</parameter></term>
379 <para>A list of field defintions. Each definition can be
380 a symbol or a list of two elements. Symbols get assigned a value of the
381 current counter which starts at <computeroutput>0</computeroutput> and
382 increments by <computeroutput>1</computeroutput> for each subsequent symbol. It the field definition is a list, the first position is the symbol and the second
383 position is the value to assign the the symbol. The current counter gets set
384 to <computeroutput>1+</computeroutput> this value.
389 <term><parameter>separator-string</parameter></term>
391 <para>A string that governs the creation of constants. The
392 default is <computeroutput>"#"</computeroutput>.</para>
398 <title>Description</title>
400 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
401 values are created by the <function>concatenation</function> of the
402 enumeration name, separator-string, and field symbol. Also creates
403 a foreign type with the name <parameter>name</parameter> of type
404 <constant>:int</constant>.
408 <title>Examples</title>
410 (def-enum abc (:a :b :c))
411 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
412 ;; the foreign type "abc" to be :int
414 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
415 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
416 ;; the foreign type efoo to be :int
420 <title>Side Effects</title>
421 <para>Creates a :int foreign type, defines constants.</para>
424 <title>Affected by</title>
428 <title>Exceptional Situations</title>
434 <refentry id="def-struct">
436 <refname>def-struct</refname>
437 <refpurpose>Defines a &c; structure.
439 <refclass>Macro</refclass>
442 <title>Syntax</title>
444 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
448 <title>Arguments and Values</title>
451 <term><parameter>name</parameter></term>
453 <para>A symbol that names the structure.
458 <term><parameter>fields</parameter></term>
460 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
467 <title>Description</title>
469 Declares a structure. A special type is available as a slot
470 in the field. It is a pointer that points to an instance of the parent
471 structure. It's type is <constant>:pointer-self</constant>.
476 <title>Examples</title>
478 (def-struct foo (a :unsigned-int)
481 (next :pointer-self))
485 <title>Side Effects</title>
486 <para>Creates a foreign type.</para>
489 <title>Affected by</title>
493 <title>Exceptional Situations</title>
499 <refentry id="get-slot-value">
501 <refname>def-slot-value</refname>
502 <refpurpose>Retrieves a value from a slot of a structure.
504 <refclass>Macro</refclass>
507 <title>Syntax</title>
509 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
513 <title>Arguments and Values</title>
516 <term><parameter>obj</parameter></term>
518 <para>A pointer to foreign structure.
523 <term><parameter>type</parameter></term>
525 <para>A name of the foreign structure.
530 <term><parameter>field</parameter></term>
532 <para>A name of the desired field in foreign structure.
537 <term><returnvalue>value</returnvalue></term>
539 <para>The value of the field in the structure.
546 <title>Description</title>
548 Accesses a slot value from a structure.
552 <title>Examples</title>
554 (get-slot-value foo-ptr 'foo-structure 'field-name)
558 <title>Side Effects</title>
562 <title>Affected by</title>
566 <title>Exceptional Situations</title>
571 <refentry id="get-slot-pointer">
573 <refname>get-slot-pointer</refname>
574 <refpurpose>Retrieves a pointer from a slot of a structure.
576 <refclass>Macro</refclass>
579 <title>Syntax</title>
581 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
585 <title>Arguments and Values</title>
588 <term><parameter>obj</parameter></term>
590 <para>A pointer to foreign structure.
595 <term><parameter>type</parameter></term>
597 <para>A name of the foreign structure.
602 <term><parameter>field</parameter></term>
604 <para>A name of the desired field in foreign structure.
609 <term><returnvalue>pointer</returnvalue></term>
611 <para>The value of the field in the structure.
618 <title>Description</title>
620 This is similar to <function>get-slot-value</function>. It
621 is used when the value of a slot is a pointer type.
625 <title>Examples</title>
627 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
631 <title>Side Effects</title>
635 <title>Affected by</title>
639 <title>Exceptional Situations</title>
645 <refentry id="def-array">
647 <refname>def-array</refname>
648 <refpurpose>Defines a foreign array type.
650 <refclass>Macro</refclass>
653 <title>Syntax</title>
655 <function>def-array</function> <replaceable>name type</replaceable>
659 <title>Arguments and Values</title>
662 <term><parameter>name</parameter></term>
664 <para>A name of the new foreign type.
669 <term><parameter>type</parameter></term>
671 <para>The foreign type of the array elements.
678 <title>Description</title>
680 Defines a foreign array type.
684 <title>Examples</title>
686 (def-array byte-array :unsigned-char)
690 <title>Side Effects</title>
691 <para>Defines a new foreign type.</para>
694 <title>Affected by</title>
698 <title>Exceptional Situations</title>
704 <refentry id="deref-array">
706 <refname>deref-array</refname>
707 <refpurpose>Deference an array.
709 <refclass>Macro</refclass>
712 <title>Syntax</title>
714 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
718 <title>Arguments and Values</title>
721 <term><parameter>array</parameter></term>
723 <para>A foreign array.
728 <term><parameter>type</parameter></term>
730 <para>The foreign type of the array.
735 <term><parameter>position</parameter></term>
737 <para>An integer specifying the position to retrieve from
743 <term><returnvalue>value</returnvalue></term>
745 <para>The value stored in the position of the array.
752 <title>Description</title>
754 Dereferences (retrieves) the value of an array element.
758 <title>Examples</title>
761 (let ((fs (convert-to-foreign-string "ab")))
762 (values (null-char-p (deref-array fs 'ca 0))
763 (null-char-p (deref-array fs 'ca 2))))
769 <title>Side Effects</title>
773 <title>Affected by</title>
777 <title>Exceptional Situations</title>
784 <title>Objects</title>
786 <title>Overview</title>
788 Objects are entities that can allocated and freed.
793 <refentry id="allocate-foreign-object">
795 <refname>allocate-foreign-object</refname>
796 <refpurpose>Allocates an instance of a foreign object.
798 <refclass>Macro</refclass>
801 <title>Syntax</title>
803 <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
807 <title>Arguments and Values</title>
810 <term><parameter>type</parameter></term>
812 <para>A type of foreign object to allocate.
817 <term><returnvalue>ptr</returnvalue></term>
819 <para>A pointer to the foreign object.
826 <title>Description</title>
828 Allocates an instance of a foreign object. It returns a pointer to the object.
832 <title>Examples</title>
834 (def-struct ab (a :int) (b :double))
835 (allocate-foreign-object 'ab)
840 <title>Side Effects</title>
844 <title>Affected by</title>
848 <title>Exceptional Situations</title>
854 <refentry id="free-foreign-object">
856 <refname>free-foreign-object</refname>
857 <refpurpose>Frees memory that was allocated for a foreign boject.
859 <refclass>Macro</refclass>
862 <title>Syntax</title>
864 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
868 <title>Arguments and Values</title>
871 <term><parameter>ptr</parameter></term>
873 <para>A pointer to the allocated foreign object to free.
880 <title>Description</title>
882 Frees the memory used by the allocation of a foreign object.
886 <title>Side Effects</title>
890 <title>Affected by</title>
894 <title>Exceptional Situations</title>
900 <refentry id="pointer-address">
902 <refname>pointer-address</refname>
903 <refpurpose>Returns the address of a pointer.
905 <refclass>Macro</refclass>
908 <title>Syntax</title>
910 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
914 <title>Arguments and Values</title>
917 <term><parameter>ptr</parameter></term>
919 <para>A pointer to a foreign object.
924 <term><parameter>address</parameter></term>
926 <para>An integer representing the pointer's address.
933 <title>Description</title>
935 Returns the address as an integer of a pointer.
939 <title>Side Effects</title>
943 <title>Affected by</title>
947 <title>Exceptional Situations</title>
953 <refentry id="deref-pointer">
955 <refname>deref-pointer</refname>
956 <refpurpose>Deferences a pointer.
958 <refclass>Macro</refclass>
961 <title>Syntax</title>
963 <function>def-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
967 <title>Arguments and Values</title>
970 <term><parameter>ptr</parameter></term>
972 <para>A pointer to a foreign object.
977 <term><parameter>type</parameter></term>
979 <para>A foreign type of the object being pointed to.
984 <term><parameter>value</parameter></term>
986 <para>The value of the object where the pointer points.
993 <title>Description</title>
995 Returns the object to which a pointer points.
999 <title>Examples</title>
1002 (let ((fs (convert-to-foreign-string "a")))
1004 (ensure-char (deref-pointer fs :char))
1005 (free-foreign-object fs)))
1011 <title>Side Effects</title>
1015 <title>Affected by</title>
1019 <title>Exceptional Situations</title>
1024 <refentry id="make-null-pointer">
1026 <refname>make-null-pointer</refname>
1027 <refpurpose>Create a &null; pointer.
1029 <refclass>Macro</refclass>
1032 <title>Syntax</title>
1034 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1038 <title>Arguments and Values</title>
1041 <term><parameter>type</parameter></term>
1043 <para>A type of object to which the pointer refers.
1048 <term><parameter>ptr</parameter></term>
1050 <para>The &null; pointer of type <parameter>type</parameter>.
1057 <title>Description</title>
1059 Creates a &null; pointer of a specified type.
1063 <title>Side Effects</title>
1067 <title>Affected by</title>
1071 <title>Exceptional Situations</title>
1077 <refentry id="null-pointer-p">
1079 <refname>null-pointer-p</refname>
1080 <refpurpose>Tests a pointer for &null; value.
1082 <refclass>Macro</refclass>
1085 <title>Syntax</title>
1087 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1091 <title>Arguments and Values</title>
1094 <term><parameter>ptr</parameter></term>
1096 <para>A foreign object pointer.
1101 <term><returnvalue>is-null</returnvalue></term>
1103 <para>The boolean flag.
1110 <title>Description</title>
1112 A predicate testing if a pointer is has a &null; value.
1116 <title>Side Effects</title>
1120 <title>Affected by</title>
1124 <title>Exceptional Situations</title>
1130 <refentry id="null-cstring-pointer">
1132 <refname>+null-cstring-pointer+</refname>
1133 <refpurpose>A constant &null; cstring pointer.
1135 <refclass>Constant</refclass>
1138 <title>Description</title>
1140 A &null; cstring pointer. This can be used for testing
1141 if a cstring returned by a function is &null;.
1149 <title>Strings</title>
1151 <title>Overview</title>
1153 &uffi; has functions to two types of <varname>C</varname>-compatible
1154 strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
1155 cstrings are used as parameters to and from functions. An implementation, such as CMUCL,
1156 may not convert these to a foreign type for efficiency sake. Thus, it is not
1157 possible to "allocate" a cstring. In contrast, foreign strings
1158 always need to have memory for them.
1162 <refentry id="convert-from-cstring">
1164 <refname>convert-from-cstring</refname>
1165 <refpurpose>Converts a cstring to a Lisp string.
1167 <refclass>Macro</refclass>
1170 <title>Syntax</title>
1172 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
1176 <title>Arguments and Values</title>
1179 <term><parameter>cstring</parameter></term>
1186 <term><returnvalue>string</returnvalue></term>
1188 <para>A Lisp string.
1195 <title>Description</title>
1197 Converts a Lisp string to a <constant>cstring</constant>. This is
1198 most often used when processing the results of a foreign function
1199 that returns a cstring.
1203 <title>Side Effects</title>
1207 <title>Affected by</title>
1211 <title>Exceptional Situations</title>
1217 <refentry id="convert-to-cstring">
1219 <refname>convert-to-cstring</refname>
1220 <refpurpose>Converts a Lisp string to a cstring.
1222 <refclass>Macro</refclass>
1225 <title>Syntax</title>
1227 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
1231 <title>Arguments and Values</title>
1234 <term><parameter>string</parameter></term>
1236 <para>A Lisp string.
1241 <term><returnvalue>cstring</returnvalue></term>
1250 <title>Description</title>
1252 Converts a Lisp string to a
1253 <varname>cstring</varname>. The
1254 <varname>cstring</varname> should be freed with
1255 <function>free-cstring</function>.
1259 <title>Side Effects</title>
1263 <title>Affected by</title>
1267 <title>Exceptional Situations</title>
1273 <refentry id="free-cstring">
1275 <refname>free-cstring</refname>
1276 <refpurpose>Free memory used by cstring.
1278 <refclass>Macro</refclass>
1281 <title>Syntax</title>
1283 <function>free-cstring</function> <replaceable>cstring</replaceable>
1287 <title>Arguments and Values</title>
1290 <term><parameter>cstring</parameter></term>
1299 <title>Description</title>
1301 Frees any memory possibly allocated by
1302 <function>convert-to-cstring</function>.
1306 <title>Side Effects</title>
1310 <title>Affected by</title>
1314 <title>Exceptional Situations</title>
1320 <refentry id="with-cstring">
1322 <refname>with-cstring</refname>
1323 <refpurpose>Binds a newly created cstring.
1325 <refclass>Macro</refclass>
1328 <title>Syntax</title>
1330 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
1334 <title>Arguments and Values</title>
1337 <term><parameter>cstring</parameter></term>
1339 <para>A symbol naming the cstring to be created.
1344 <term><parameter>string</parameter></term>
1346 <para>A Lisp string that will be translated to a cstring.
1351 <term><parameter>body</parameter></term>
1353 <para>The body of where the cstring will be bound.
1360 <title>Description</title>
1362 Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
1366 <title>Examples</title>
1369 (def-function ("getenv" c-getenv)
1371 :returning :cstring)
1374 "Returns an environment variable, or NIL if it does not exist"
1375 (check-type key string)
1376 (with-cstring (key-cstring key)
1377 (convert-from-cstring (c-getenv key-cstring))))
1382 <title>Side Effects</title>
1386 <title>Affected by</title>
1390 <title>Exceptional Situations</title>
1396 <refentry id="convert-from-foreign-string">
1398 <refname>convert-from-foreign-string</refname>
1399 <refpurpose>Converts a foreign string into a Lisp string.
1401 <refclass>Macro</refclass>
1404 <title>Syntax</title>
1406 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
1410 <title>Arguments and Values</title>
1413 <term><parameter>foreign-string</parameter></term>
1415 <para>A foreign string.
1420 <term><parameter>length</parameter></term>
1422 <para>The length of the foreign string to
1423 convert. The default is the length of the string until a &null;
1424 character is reached.
1429 <term><parameter>null-terminated-p</parameter></term>
1431 <para>A boolean flag with a default value of &t; When true,
1432 the string is converted until the first &null; character is reached.
1437 <term><returnvalue>string</returnvalue></term>
1439 <para>A Lisp string.
1446 <title>Description</title>
1448 Returns a Lisp string from a foreign string.
1449 Can translated ASCII and binary strings.
1453 <title>Side Effects</title>
1457 <title>Affected by</title>
1461 <title>Exceptional Situations</title>
1467 <refentry id="convert-to-foreign-string">
1469 <refname>convert-to-foreign-string</refname>
1470 <refpurpose>Converts a Lisp string to a foreign string.
1472 <refclass>Macro</refclass>
1475 <title>Syntax</title>
1477 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
1481 <title>Arguments and Values</title>
1484 <term><parameter>string</parameter></term>
1486 <para>A Lisp string.
1491 <term><returnvalue>foreign-string</returnvalue></term>
1493 <para>A foreign string.
1500 <title>Description</title>
1502 Converts a Lisp string to a foreign string. Memory should be
1503 freed with <function>free-foreign-object</function>.
1507 <title>Side Effects</title>
1511 <title>Affected by</title>
1515 <title>Exceptional Situations</title>
1522 <refentry id="allocate-foreign-string">
1524 <refname>allocate-foreign-string</refname>
1525 <refpurpose>Allocates space for a foreign string.
1527 <refclass>Macro</refclass>
1530 <title>Syntax</title>
1532 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
1536 <title>Arguments and Values</title>
1539 <term><parameter>size</parameter></term>
1541 <para>The size of the space to be allocated in bytes.
1546 <term><parameter>unsigned</parameter></term>
1548 <para>A boolean flag with a default value of &t;. When true,
1549 marks the pointer as an <constant>:unsigned-char</constant>.
1554 <term><returnvalue>foreign-string</returnvalue></term>
1556 <para>A foreign string which has undefined contents.
1563 <title>Description</title>
1565 Allocates space for a foreign string. Memory should
1566 be freed with <function>free-foreign-object</function>.
1570 <title>Side Effects</title>
1574 <title>Affected by</title>
1578 <title>Exceptional Situations</title>
1586 <title>Functions & Libraries</title>
1588 <refentry id="def-function">
1590 <refname>def-function</refname>
1591 <refpurpose>Declares a function.
1593 <refclass>Macro</refclass>
1596 <title>Syntax</title>
1598 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
1602 <title>Arguments and Values</title>
1605 <term><parameter>name</parameter></term>
1607 <para>A string or list specificying the function name. If it is a string, that names the foreign function. A Lisp name is created by translating #\_ to #\- and by converting to upper-case in case-insensitive Lisp implementations. If it is a list, the first item is a string specifying the foreign function name and the second it is a symbol stating the Lisp name.
1612 <term><parameter>args</parameter></term>
1614 <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
1619 <term><parameter>module</parameter></term>
1621 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
1625 <term><returnvalue>returning</returnvalue></term>
1627 <para>A declaration specifying the result type of the
1628 foreign function. If <constant>:void</constant> indicates module does not return any value.
1635 <title>Description</title>
1636 <para>Declares a foreign function.
1640 <title>Examples</title>
1642 (def-function "gethostname"
1649 <title>Side Effects</title>
1653 <title>Affected by</title>
1657 <title>Exceptional Situations</title>
1662 <refentry id="load-foreign-library">
1664 <refname>load-foreign-library</refname>
1665 <refpurpose>Loads a foreign library.
1667 <refclass>Function</refclass>
1670 <title>Syntax</title>
1672 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
1676 <title>Arguments and Values</title>
1679 <term><parameter>filename</parameter></term>
1681 <para>A string or pathname specifying the library location
1682 in the filesystem. At least one implementation (&lw;) can not
1683 accept a logical pathname.
1688 <term><parameter>module</parameter></term>
1690 <para>A string designating the name of the module to apply
1691 to functions in this library. (Required for Lispworks)
1696 <term><parameter>supporting-libraries</parameter></term>
1698 <para>A list of strings naming the libraries required to
1699 link the foreign library. (Required by CMUCL)
1704 <term><returnvalue>success</returnvalue></term>
1706 <para>A boolean flag, &t; if the library was able to be
1707 loaded successfully or if the library has been previously loaded,
1715 <title>Description</title>
1716 <para>Loads a foreign library. Applies a module name to functions
1717 within the library. Ensures that a library is only loaded once during
1722 <title>Examples</title>
1724 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
1726 :supporting-libraries '("c"))
1731 <title>Side Effects</title>
1732 <para>Loads the foreign code into the Lisp system.
1736 <title>Affected by</title>
1737 <para>Ability to load the file.</para>
1740 <title>Exceptional Situations</title>