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>
95 <para><constant>:unsigned-char</constant> - Unsigned 8-bits. A dereferenced :unsigned-char
96 pointer returns an character.</para>
99 <para><constant>:byte</constant> - Unsigned 8-bits. A
100 dereferenced :byte pointer returns an integer.</para>
103 <para><constant>:short</constant> - Signed 16-bits.</para>
106 <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
109 <para><constant>:int</constant> - Signed 32-bits.</para>
112 <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
115 <para><constant>:long</constant> - Signed 32-bits.</para>
118 <para><constant>:unsigned-long</constant> - Unsigned 32-bits.</para>
121 <para><constant>:float</constant> - 32-bit floating point.</para>
124 <para><constant>:double</constant> - 64-bit floating point.</para>
127 <para><constant>:cstring</constant> -
128 A &null; terminated string used for passing and returning characters strings with a &c; function.
132 <para><constant>:void</constant> -
133 The absence of a value. Used to indicate that a function does not return a value.</para>
136 <para><constant>:pointer-void</constant> -
137 Points to a generic object.</para>
140 <para><constant>*</constant> - Used to declare a pointer to an object</para>
145 <refentry id="def-constant">
147 <refname>def-constant</refname>
148 <refpurpose>Binds a symbol to a constant.
150 <refclass>Macro</refclass>
153 <title>Syntax</title>
155 <function>def-constant</function> <replaceable>name value &key export</replaceable>
159 <title>Arguments and Values</title>
162 <term><parameter>name</parameter></term>
164 <para>A symbol that will be bound to the value.
169 <term><parameter>value</parameter></term>
171 <para>An evaluated form that is bound the the name.
176 <term><parameter>export</parameter></term>
178 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
184 <title>Description</title>
186 This is a thin wrapper around
187 <function>defconstant</function>. It evaluates at
188 compile-time and optionally exports the symbol from the package.
192 <title>Examples</title>
194 (def-constant pi2 (* 2 pi))
195 (def-constant exported-pi2 (* 2 pi) :export t)
199 <title>Side Effects</title>
200 <para>Creates a new special variable..</para>
203 <title>Affected by</title>
207 <title>Exceptional Situations</title>
212 <refentry id="def-foreign-type">
214 <refname>def-foreign-type</refname>
215 <refpurpose>Defines a new foreign type.
217 <refclass>Macro</refclass>
220 <title>Syntax</title>
222 <function>def-foreign-type</function> <replaceable>name type</replaceable>
226 <title>Arguments and Values</title>
229 <term><parameter>name</parameter></term>
231 <para>A symbol naming the new foreign type.
236 <term><parameter>value</parameter></term>
238 <para>A form that is not evaluated that defines the new
246 <title>Description</title>
247 <para>Defines a new foreign type.
251 <title>Examples</title>
253 (def-foreign-type my-generic-pointer :pointer-void)
254 (def-foreign-type a-double-float :double-float)
255 (def-foreign-type char-ptr (* :char))
259 <title>Side Effects</title>
260 <para>Defines a new foreign type.
264 <title>Affected by</title>
268 <title>Exceptional Situations</title>
273 <refentry id="null-char-p">
275 <refname>null-char-p</refname>
276 <refpurpose>Tests a character for &null; value.
278 <refclass>Macro</refclass>
281 <title>Syntax</title>
283 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
287 <title>Arguments and Values</title>
290 <term><parameter>char</parameter></term>
292 <para>A character or integer.
297 <term><parameter>is-null</parameter></term>
299 <para>A boolean flag indicating if char is a &null; value.
306 <title>Description</title>
308 A predicate testing if a character or integer is &null;. This
309 abstracts the difference in implementations where some return a
310 <computeroutput>character</computeroutput> and some return a
311 <computeroutput>integer</computeroutput> whence dereferencing a
312 <computeroutput>C</computeroutput> character pointer.
316 <title>Examples</title>
319 (let ((fs (convert-to-foreign-string "ab")))
320 (values (null-char-p (deref-array fs 'ca 0))
321 (null-char-p (deref-array fs 'ca 2))))
327 <title>Side Effects</title>
332 <title>Affected by</title>
336 <title>Exceptional Situations</title>
343 <title>Aggregate Types</title>
345 <title>Overview</title>
347 Aggregate types are comprised of one or more primitive types.
351 <refentry id="def-enum">
353 <refname>def-enum</refname>
354 <refpurpose>Defines a &c; enumeration.
356 <refclass>Macro</refclass>
359 <title>Syntax</title>
361 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
365 <title>Arguments and Values</title>
368 <term><parameter>name</parameter></term>
370 <para>A symbol that names the enumeration.
375 <term><parameter>fields</parameter></term>
377 <para>A list of field defintions. Each definition can be
378 a symbol or a list of two elements. Symbols get assigned a value of the
379 current counter which starts at <computeroutput>0</computeroutput> and
380 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
381 position is the value to assign the the symbol. The current counter gets set
382 to <computeroutput>1+</computeroutput> this value.
387 <term><parameter>separator-string</parameter></term>
389 <para>A string that governs the creation of constants. The
390 default is <computeroutput>"#"</computeroutput>.</para>
396 <title>Description</title>
398 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
399 values are created by the <function>concatenation</function> of the
400 enumeration name, separator-string, and field symbol. Also creates
401 a foreign type with the name <parameter>name</parameter> of type
402 <constant>:int</constant>.
406 <title>Examples</title>
408 (def-enum abc (:a :b :c))
409 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
410 ;; the foreign type "abc" to be :int
412 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
413 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
414 ;; the foreign type efoo to be :int
418 <title>Side Effects</title>
419 <para>Creates a :int foreign type, defines constants.</para>
422 <title>Affected by</title>
426 <title>Exceptional Situations</title>
432 <refentry id="def-struct">
434 <refname>def-struct</refname>
435 <refpurpose>Defines a &c; structure.
437 <refclass>Macro</refclass>
440 <title>Syntax</title>
442 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
446 <title>Arguments and Values</title>
449 <term><parameter>name</parameter></term>
451 <para>A symbol that names the structure.
456 <term><parameter>fields</parameter></term>
458 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
465 <title>Description</title>
467 Declares a structure. A special type is available as a slot
468 in the field. It is a pointer that points to an instance of the parent
469 structure. It's type is <constant>:pointer-self</constant>.
474 <title>Examples</title>
476 (def-struct foo (a :unsigned-int)
479 (next :pointer-self))
483 <title>Side Effects</title>
484 <para>Creates a foreign type.</para>
487 <title>Affected by</title>
491 <title>Exceptional Situations</title>
497 <refentry id="get-slot-value">
499 <refname>get-slot-value</refname>
500 <refpurpose>Retrieves a value from a slot of a structure.
502 <refclass>Macro</refclass>
505 <title>Syntax</title>
507 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
511 <title>Arguments and Values</title>
514 <term><parameter>obj</parameter></term>
516 <para>A pointer to foreign structure.
521 <term><parameter>type</parameter></term>
523 <para>A name of the foreign structure.
528 <term><parameter>field</parameter></term>
530 <para>A name of the desired field in foreign structure.
535 <term><returnvalue>value</returnvalue></term>
537 <para>The value of the field in the structure.
544 <title>Description</title>
546 Accesses a slot value from a structure.
550 <title>Examples</title>
552 (get-slot-value foo-ptr 'foo-structure 'field-name)
556 <title>Side Effects</title>
560 <title>Affected by</title>
564 <title>Exceptional Situations</title>
569 <refentry id="get-slot-pointer">
571 <refname>get-slot-pointer</refname>
572 <refpurpose>Retrieves a pointer from a slot of a structure.
574 <refclass>Macro</refclass>
577 <title>Syntax</title>
579 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
583 <title>Arguments and Values</title>
586 <term><parameter>obj</parameter></term>
588 <para>A pointer to foreign structure.
593 <term><parameter>type</parameter></term>
595 <para>A name of the foreign structure.
600 <term><parameter>field</parameter></term>
602 <para>A name of the desired field in foreign structure.
607 <term><returnvalue>pointer</returnvalue></term>
609 <para>The value of the field in the structure.
616 <title>Description</title>
618 This is similar to <function>get-slot-value</function>. It
619 is used when the value of a slot is a pointer type.
623 <title>Examples</title>
625 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
629 <title>Side Effects</title>
633 <title>Affected by</title>
637 <title>Exceptional Situations</title>
643 <refentry id="def-array">
645 <refname>def-array</refname>
646 <refpurpose>Defines a foreign array type.
648 <refclass>Macro</refclass>
651 <title>Syntax</title>
653 <function>def-array</function> <replaceable>name type</replaceable>
657 <title>Arguments and Values</title>
660 <term><parameter>name</parameter></term>
662 <para>A name of the new foreign type.
667 <term><parameter>type</parameter></term>
669 <para>The foreign type of the array elements.
676 <title>Description</title>
678 Defines a foreign array type.
682 <title>Examples</title>
684 (def-array byte-array :unsigned-char)
688 <title>Side Effects</title>
689 <para>Defines a new foreign type.</para>
692 <title>Affected by</title>
696 <title>Exceptional Situations</title>
702 <refentry id="deref-array">
704 <refname>deref-array</refname>
705 <refpurpose>Deference an array.
707 <refclass>Macro</refclass>
710 <title>Syntax</title>
712 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
716 <title>Arguments and Values</title>
719 <term><parameter>array</parameter></term>
721 <para>A foreign array.
726 <term><parameter>type</parameter></term>
728 <para>The foreign type of the array.
733 <term><parameter>position</parameter></term>
735 <para>An integer specifying the position to retrieve from
741 <term><returnvalue>value</returnvalue></term>
743 <para>The value stored in the position of the array.
750 <title>Description</title>
752 Dereferences (retrieves) the value of an array element.
756 <title>Examples</title>
759 (let ((fs (convert-to-foreign-string "ab")))
760 (values (null-char-p (deref-array fs 'ca 0))
761 (null-char-p (deref-array fs 'ca 2))))
767 <title>Side Effects</title>
771 <title>Affected by</title>
775 <title>Exceptional Situations</title>
782 <title>Objects</title>
784 <title>Overview</title>
786 Objects are entities that can allocated and freed.
791 <refentry id="allocate-foreign-object">
793 <refname>allocate-foreign-object</refname>
794 <refpurpose>Allocates an instance of a foreign object.
796 <refclass>Macro</refclass>
799 <title>Syntax</title>
801 <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
805 <title>Arguments and Values</title>
808 <term><parameter>type</parameter></term>
810 <para>A type of foreign object to allocate.
815 <term><returnvalue>ptr</returnvalue></term>
817 <para>A pointer to the foreign object.
824 <title>Description</title>
826 Allocates an instance of a foreign object. It returns a pointer to the object.
830 <title>Examples</title>
832 (def-struct ab (a :int) (b :double))
833 (allocate-foreign-object ab)
838 <title>Side Effects</title>
842 <title>Affected by</title>
846 <title>Exceptional Situations</title>
852 <refentry id="free-foreign-object">
854 <refname>free-foreign-object</refname>
855 <refpurpose>Frees memory that was allocated for a foreign boject.
857 <refclass>Macro</refclass>
860 <title>Syntax</title>
862 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
866 <title>Arguments and Values</title>
869 <term><parameter>ptr</parameter></term>
871 <para>A pointer to the allocated foreign object to free.
878 <title>Description</title>
880 Frees the memory used by the allocation of a foreign object.
884 <title>Side Effects</title>
888 <title>Affected by</title>
892 <title>Exceptional Situations</title>
898 <refentry id="pointer-address">
900 <refname>pointer-address</refname>
901 <refpurpose>Returns the address of a pointer.
903 <refclass>Macro</refclass>
906 <title>Syntax</title>
908 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
912 <title>Arguments and Values</title>
915 <term><parameter>ptr</parameter></term>
917 <para>A pointer to a foreign object.
922 <term><parameter>address</parameter></term>
924 <para>An integer representing the pointer's address.
931 <title>Description</title>
933 Returns the address as an integer of a pointer.
937 <title>Side Effects</title>
941 <title>Affected by</title>
945 <title>Exceptional Situations</title>
951 <refentry id="deref-pointer">
953 <refname>deref-pointer</refname>
954 <refpurpose>Deferences a pointer.
956 <refclass>Macro</refclass>
959 <title>Syntax</title>
961 <function>deref-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
965 <title>Arguments and Values</title>
968 <term><parameter>ptr</parameter></term>
970 <para>A pointer to a foreign object.
975 <term><parameter>type</parameter></term>
977 <para>A foreign type of the object being pointed to.
982 <term><parameter>value</parameter></term>
984 <para>The value of the object where the pointer points.
991 <title>Description</title>
993 Returns the object to which a pointer points.
997 <title>Examples</title>
1000 (let ((fs (convert-to-foreign-string "a")))
1002 (ensure-char (deref-pointer fs :char))
1003 (free-foreign-object fs)))
1009 <title>Side Effects</title>
1013 <title>Affected by</title>
1017 <title>Exceptional Situations</title>
1022 <refentry id="make-null-pointer">
1024 <refname>make-null-pointer</refname>
1025 <refpurpose>Create a &null; pointer.
1027 <refclass>Macro</refclass>
1030 <title>Syntax</title>
1032 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1036 <title>Arguments and Values</title>
1039 <term><parameter>type</parameter></term>
1041 <para>A type of object to which the pointer refers.
1046 <term><parameter>ptr</parameter></term>
1048 <para>The &null; pointer of type <parameter>type</parameter>.
1055 <title>Description</title>
1057 Creates a &null; pointer of a specified type.
1061 <title>Side Effects</title>
1065 <title>Affected by</title>
1069 <title>Exceptional Situations</title>
1075 <refentry id="null-pointer-p">
1077 <refname>null-pointer-p</refname>
1078 <refpurpose>Tests a pointer for &null; value.
1080 <refclass>Macro</refclass>
1083 <title>Syntax</title>
1085 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1089 <title>Arguments and Values</title>
1092 <term><parameter>ptr</parameter></term>
1094 <para>A foreign object pointer.
1099 <term><returnvalue>is-null</returnvalue></term>
1101 <para>The boolean flag.
1108 <title>Description</title>
1110 A predicate testing if a pointer is has a &null; value.
1114 <title>Side Effects</title>
1118 <title>Affected by</title>
1122 <title>Exceptional Situations</title>
1128 <refentry id="null-cstring-pointer">
1130 <refname>+null-cstring-pointer+</refname>
1131 <refpurpose>A constant &null; cstring pointer.
1133 <refclass>Constant</refclass>
1136 <title>Description</title>
1138 A &null; cstring pointer. This can be used for testing
1139 if a cstring returned by a function is &null;.
1147 <title>Strings</title>
1149 <title>Overview</title>
1151 &uffi; has functions to two types of <varname>C</varname>-compatible
1152 strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
1153 cstrings are used as parameters to and from functions. An implementation, such as CMUCL,
1154 may not convert these to a foreign type for efficiency sake. Thus, it is not
1155 possible to "allocate" a cstring. In contrast, foreign strings
1156 always need to have memory for them.
1160 <refentry id="convert-from-cstring">
1162 <refname>convert-from-cstring</refname>
1163 <refpurpose>Converts a cstring to a Lisp string.
1165 <refclass>Macro</refclass>
1168 <title>Syntax</title>
1170 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
1174 <title>Arguments and Values</title>
1177 <term><parameter>cstring</parameter></term>
1184 <term><returnvalue>string</returnvalue></term>
1186 <para>A Lisp string.
1193 <title>Description</title>
1195 Converts a Lisp string to a <constant>cstring</constant>. This is
1196 most often used when processing the results of a foreign function
1197 that returns a cstring.
1201 <title>Side Effects</title>
1205 <title>Affected by</title>
1209 <title>Exceptional Situations</title>
1215 <refentry id="convert-to-cstring">
1217 <refname>convert-to-cstring</refname>
1218 <refpurpose>Converts a Lisp string to a cstring.
1220 <refclass>Macro</refclass>
1223 <title>Syntax</title>
1225 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
1229 <title>Arguments and Values</title>
1232 <term><parameter>string</parameter></term>
1234 <para>A Lisp string.
1239 <term><returnvalue>cstring</returnvalue></term>
1248 <title>Description</title>
1250 Converts a Lisp string to a
1251 <varname>cstring</varname>. The
1252 <varname>cstring</varname> should be freed with
1253 <function>free-cstring</function>.
1257 <title>Side Effects</title>
1261 <title>Affected by</title>
1265 <title>Exceptional Situations</title>
1271 <refentry id="free-cstring">
1273 <refname>free-cstring</refname>
1274 <refpurpose>Free memory used by cstring.
1276 <refclass>Macro</refclass>
1279 <title>Syntax</title>
1281 <function>free-cstring</function> <replaceable>cstring</replaceable>
1285 <title>Arguments and Values</title>
1288 <term><parameter>cstring</parameter></term>
1297 <title>Description</title>
1299 Frees any memory possibly allocated by
1300 <function>convert-to-cstring</function>.
1304 <title>Side Effects</title>
1308 <title>Affected by</title>
1312 <title>Exceptional Situations</title>
1318 <refentry id="with-cstring">
1320 <refname>with-cstring</refname>
1321 <refpurpose>Binds a newly created cstring.
1323 <refclass>Macro</refclass>
1326 <title>Syntax</title>
1328 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
1332 <title>Arguments and Values</title>
1335 <term><parameter>cstring</parameter></term>
1337 <para>A symbol naming the cstring to be created.
1342 <term><parameter>string</parameter></term>
1344 <para>A Lisp string that will be translated to a cstring.
1349 <term><parameter>body</parameter></term>
1351 <para>The body of where the cstring will be bound.
1358 <title>Description</title>
1360 Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
1364 <title>Examples</title>
1367 (def-function ("getenv" c-getenv)
1369 :returning :cstring)
1372 "Returns an environment variable, or NIL if it does not exist"
1373 (check-type key string)
1374 (with-cstring (key-cstring key)
1375 (convert-from-cstring (c-getenv key-cstring))))
1380 <title>Side Effects</title>
1384 <title>Affected by</title>
1388 <title>Exceptional Situations</title>
1394 <refentry id="convert-from-foreign-string">
1396 <refname>convert-from-foreign-string</refname>
1397 <refpurpose>Converts a foreign string into a Lisp string.
1399 <refclass>Macro</refclass>
1402 <title>Syntax</title>
1404 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
1408 <title>Arguments and Values</title>
1411 <term><parameter>foreign-string</parameter></term>
1413 <para>A foreign string.
1418 <term><parameter>length</parameter></term>
1420 <para>The length of the foreign string to
1421 convert. The default is the length of the string until a &null;
1422 character is reached.
1427 <term><parameter>null-terminated-p</parameter></term>
1429 <para>A boolean flag with a default value of &t; When true,
1430 the string is converted until the first &null; character is reached.
1435 <term><returnvalue>string</returnvalue></term>
1437 <para>A Lisp string.
1444 <title>Description</title>
1446 Returns a Lisp string from a foreign string.
1447 Can translated ASCII and binary strings.
1451 <title>Side Effects</title>
1455 <title>Affected by</title>
1459 <title>Exceptional Situations</title>
1465 <refentry id="convert-to-foreign-string">
1467 <refname>convert-to-foreign-string</refname>
1468 <refpurpose>Converts a Lisp string to a foreign string.
1470 <refclass>Macro</refclass>
1473 <title>Syntax</title>
1475 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
1479 <title>Arguments and Values</title>
1482 <term><parameter>string</parameter></term>
1484 <para>A Lisp string.
1489 <term><returnvalue>foreign-string</returnvalue></term>
1491 <para>A foreign string.
1498 <title>Description</title>
1500 Converts a Lisp string to a foreign string. Memory should be
1501 freed with <function>free-foreign-object</function>.
1505 <title>Side Effects</title>
1509 <title>Affected by</title>
1513 <title>Exceptional Situations</title>
1520 <refentry id="allocate-foreign-string">
1522 <refname>allocate-foreign-string</refname>
1523 <refpurpose>Allocates space for a foreign string.
1525 <refclass>Macro</refclass>
1528 <title>Syntax</title>
1530 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
1534 <title>Arguments and Values</title>
1537 <term><parameter>size</parameter></term>
1539 <para>The size of the space to be allocated in bytes.
1544 <term><parameter>unsigned</parameter></term>
1546 <para>A boolean flag with a default value of &t;. When true,
1547 marks the pointer as an <constant>:unsigned-char</constant>.
1552 <term><returnvalue>foreign-string</returnvalue></term>
1554 <para>A foreign string which has undefined contents.
1561 <title>Description</title>
1563 Allocates space for a foreign string. Memory should
1564 be freed with <function>free-foreign-object</function>.
1568 <title>Side Effects</title>
1572 <title>Affected by</title>
1576 <title>Exceptional Situations</title>
1584 <title>Functions & Libraries</title>
1586 <refentry id="def-function">
1588 <refname>def-function</refname>
1589 <refpurpose>Declares a function.
1591 <refclass>Macro</refclass>
1594 <title>Syntax</title>
1596 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
1600 <title>Arguments and Values</title>
1603 <term><parameter>name</parameter></term>
1605 <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.
1610 <term><parameter>args</parameter></term>
1612 <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
1617 <term><parameter>module</parameter></term>
1619 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
1623 <term><returnvalue>returning</returnvalue></term>
1625 <para>A declaration specifying the result type of the
1626 foreign function. If <constant>:void</constant> indicates module does not return any value.
1633 <title>Description</title>
1634 <para>Declares a foreign function.
1638 <title>Examples</title>
1640 (def-function "gethostname"
1647 <title>Side Effects</title>
1651 <title>Affected by</title>
1655 <title>Exceptional Situations</title>
1660 <refentry id="load-foreign-library">
1662 <refname>load-foreign-library</refname>
1663 <refpurpose>Loads a foreign library.
1665 <refclass>Function</refclass>
1668 <title>Syntax</title>
1670 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
1674 <title>Arguments and Values</title>
1677 <term><parameter>filename</parameter></term>
1679 <para>A string or pathname specifying the library location
1680 in the filesystem. At least one implementation (&lw;) can not
1681 accept a logical pathname.
1686 <term><parameter>module</parameter></term>
1688 <para>A string designating the name of the module to apply
1689 to functions in this library. (Required for Lispworks)
1694 <term><parameter>supporting-libraries</parameter></term>
1696 <para>A list of strings naming the libraries required to
1697 link the foreign library. (Required by CMUCL)
1702 <term><returnvalue>success</returnvalue></term>
1704 <para>A boolean flag, &t; if the library was able to be
1705 loaded successfully or if the library has been previously loaded,
1713 <title>Description</title>
1714 <para>Loads a foreign library. Applies a module name to functions
1715 within the library. Ensures that a library is only loaded once during
1720 <title>Examples</title>
1722 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
1724 :supporting-libraries '("c"))
1729 <title>Side Effects</title>
1730 <para>Loads the foreign code into the Lisp system.
1734 <title>Affected by</title>
1735 <para>Ability to load the file.</para>
1738 <title>Exceptional Situations</title>