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>
100 <para><constant>:byte</constant> - Unsigned 8-bits. A
101 dereferenced :byte pointer returns an integer.</para>
104 <para><constant>:short</constant> - Signed 16-bits.</para>
107 <para><constant>:unsigned-short</constant> - Unsigned 16-bits.</para>
110 <para><constant>:int</constant> - Signed 32-bits.</para>
113 <para><constant>:unsigned-int</constant> - Unsigned 32-bits.</para>
116 <para><constant>:long</constant> - Signed 32-bits.</para>
119 <para><constant>:unsigned-long</constant> - Unsigned 32-bits.</para>
122 <para><constant>:float</constant> - 32-bit floating point.</para>
125 <para><constant>:double</constant> - 64-bit floating point.</para>
128 <para><constant>:cstring</constant> -
129 A &null; terminated string used for passing and returning characters strings with a &c; function.
133 <para><constant>:void</constant> -
134 The absence of a value. Used to indicate that a function does not return a value.</para>
137 <para><constant>:pointer-void</constant> -
138 Points to a generic object.</para>
141 <para><constant>*</constant> - Used to declare a pointer to an object</para>
146 <refentry id="def-constant">
148 <refname>def-constant</refname>
149 <refpurpose>Binds a symbol to a constant.
151 <refclass>Macro</refclass>
154 <title>Syntax</title>
156 <function>def-constant</function> <replaceable>name value &key export</replaceable>
160 <title>Arguments and Values</title>
163 <term><parameter>name</parameter></term>
165 <para>A symbol that will be bound to the value.
170 <term><parameter>value</parameter></term>
172 <para>An evaluated form that is bound the the name.
177 <term><parameter>export</parameter></term>
179 <para>When &t;, the name is exported from the current package. The default is &nil;</para>
185 <title>Description</title>
187 This is a thin wrapper around
188 <function>defconstant</function>. It evaluates at
189 compile-time and optionally exports the symbol from the package.
193 <title>Examples</title>
195 (def-constant pi2 (* 2 pi))
196 (def-constant exported-pi2 (* 2 pi) :export t)
200 <title>Side Effects</title>
201 <para>Creates a new special variable..</para>
204 <title>Affected by</title>
208 <title>Exceptional Situations</title>
213 <refentry id="def-foreign-type">
215 <refname>def-foreign-type</refname>
216 <refpurpose>Defines a new foreign type.
218 <refclass>Macro</refclass>
221 <title>Syntax</title>
223 <function>def-foreign-type</function> <replaceable>name type</replaceable>
227 <title>Arguments and Values</title>
230 <term><parameter>name</parameter></term>
232 <para>A symbol naming the new foreign type.
237 <term><parameter>value</parameter></term>
239 <para>A form that is not evaluated that defines the new
247 <title>Description</title>
248 <para>Defines a new foreign type.
252 <title>Examples</title>
254 (def-foreign-type my-generic-pointer :pointer-void)
255 (def-foreign-type a-double-float :double-float)
256 (def-foreign-type char-ptr (* :char))
260 <title>Side Effects</title>
261 <para>Defines a new foreign type.
265 <title>Affected by</title>
269 <title>Exceptional Situations</title>
274 <refentry id="null-char-p">
276 <refname>null-char-p</refname>
277 <refpurpose>Tests a character for &null; value.
279 <refclass>Macro</refclass>
282 <title>Syntax</title>
284 <function>null-char-p</function> <replaceable>char</replaceable> => <returnvalue>is-null</returnvalue>
288 <title>Arguments and Values</title>
291 <term><parameter>char</parameter></term>
293 <para>A character or integer.
298 <term><parameter>is-null</parameter></term>
300 <para>A boolean flag indicating if char is a &null; value.
307 <title>Description</title>
309 A predicate testing if a character or integer is &null;. This
310 abstracts the difference in implementations where some return a
311 <computeroutput>character</computeroutput> and some return a
312 <computeroutput>integer</computeroutput> whence dereferencing a
313 <computeroutput>C</computeroutput> character pointer.
317 <title>Examples</title>
320 (let ((fs (convert-to-foreign-string "ab")))
321 (values (null-char-p (deref-array fs 'ca 0))
322 (null-char-p (deref-array fs 'ca 2))))
328 <title>Side Effects</title>
333 <title>Affected by</title>
337 <title>Exceptional Situations</title>
344 <title>Aggregate Types</title>
346 <title>Overview</title>
348 Aggregate types are comprised of one or more primitive types.
352 <refentry id="def-enum">
354 <refname>def-enum</refname>
355 <refpurpose>Defines a &c; enumeration.
357 <refclass>Macro</refclass>
360 <title>Syntax</title>
362 <function>def-enum</function> <replaceable>name fields &key separator-string</replaceable>
366 <title>Arguments and Values</title>
369 <term><parameter>name</parameter></term>
371 <para>A symbol that names the enumeration.
376 <term><parameter>fields</parameter></term>
378 <para>A list of field defintions. Each definition can be
379 a symbol or a list of two elements. Symbols get assigned a value of the
380 current counter which starts at <computeroutput>0</computeroutput> and
381 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
382 position is the value to assign the the symbol. The current counter gets set
383 to <computeroutput>1+</computeroutput> this value.
388 <term><parameter>separator-string</parameter></term>
390 <para>A string that governs the creation of constants. The
391 default is <computeroutput>"#"</computeroutput>.</para>
397 <title>Description</title>
399 Declares a &c; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
400 values are created by the <function>concatenation</function> of the
401 enumeration name, separator-string, and field symbol. Also creates
402 a foreign type with the name <parameter>name</parameter> of type
403 <constant>:int</constant>.
407 <title>Examples</title>
409 (def-enum abc (:a :b :c))
410 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
411 ;; the foreign type "abc" to be :int
413 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
414 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
415 ;; the foreign type efoo to be :int
419 <title>Side Effects</title>
420 <para>Creates a :int foreign type, defines constants.</para>
423 <title>Affected by</title>
427 <title>Exceptional Situations</title>
433 <refentry id="def-struct">
435 <refname>def-struct</refname>
436 <refpurpose>Defines a &c; structure.
438 <refclass>Macro</refclass>
441 <title>Syntax</title>
443 <function>def-struct</function> <replaceable>name &rest fields</replaceable>
447 <title>Arguments and Values</title>
450 <term><parameter>name</parameter></term>
452 <para>A symbol that names the structure.
457 <term><parameter>fields</parameter></term>
459 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
466 <title>Description</title>
468 Declares a structure. A special type is available as a slot
469 in the field. It is a pointer that points to an instance of the parent
470 structure. It's type is <constant>:pointer-self</constant>.
475 <title>Examples</title>
477 (def-struct foo (a :unsigned-int)
480 (next :pointer-self))
484 <title>Side Effects</title>
485 <para>Creates a foreign type.</para>
488 <title>Affected by</title>
492 <title>Exceptional Situations</title>
498 <refentry id="get-slot-value">
500 <refname>def-slot-value</refname>
501 <refpurpose>Retrieves a value from a slot of a structure.
503 <refclass>Macro</refclass>
506 <title>Syntax</title>
508 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
512 <title>Arguments and Values</title>
515 <term><parameter>obj</parameter></term>
517 <para>A pointer to foreign structure.
522 <term><parameter>type</parameter></term>
524 <para>A name of the foreign structure.
529 <term><parameter>field</parameter></term>
531 <para>A name of the desired field in foreign structure.
536 <term><returnvalue>value</returnvalue></term>
538 <para>The value of the field in the structure.
545 <title>Description</title>
547 Accesses a slot value from a structure.
551 <title>Examples</title>
553 (get-slot-value foo-ptr 'foo-structure 'field-name)
557 <title>Side Effects</title>
561 <title>Affected by</title>
565 <title>Exceptional Situations</title>
570 <refentry id="get-slot-pointer">
572 <refname>get-slot-pointer</refname>
573 <refpurpose>Retrieves a pointer from a slot of a structure.
575 <refclass>Macro</refclass>
578 <title>Syntax</title>
580 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
584 <title>Arguments and Values</title>
587 <term><parameter>obj</parameter></term>
589 <para>A pointer to foreign structure.
594 <term><parameter>type</parameter></term>
596 <para>A name of the foreign structure.
601 <term><parameter>field</parameter></term>
603 <para>A name of the desired field in foreign structure.
608 <term><returnvalue>pointer</returnvalue></term>
610 <para>The value of the field in the structure.
617 <title>Description</title>
619 This is similar to <function>get-slot-value</function>. It
620 is used when the value of a slot is a pointer type.
624 <title>Examples</title>
626 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)
630 <title>Side Effects</title>
634 <title>Affected by</title>
638 <title>Exceptional Situations</title>
644 <refentry id="def-array">
646 <refname>def-array</refname>
647 <refpurpose>Defines a foreign array type.
649 <refclass>Macro</refclass>
652 <title>Syntax</title>
654 <function>def-array</function> <replaceable>name type</replaceable>
658 <title>Arguments and Values</title>
661 <term><parameter>name</parameter></term>
663 <para>A name of the new foreign type.
668 <term><parameter>type</parameter></term>
670 <para>The foreign type of the array elements.
677 <title>Description</title>
679 Defines a foreign array type.
683 <title>Examples</title>
685 (def-array byte-array :unsigned-char)
689 <title>Side Effects</title>
690 <para>Defines a new foreign type.</para>
693 <title>Affected by</title>
697 <title>Exceptional Situations</title>
703 <refentry id="deref-array">
705 <refname>deref-array</refname>
706 <refpurpose>Deference an array.
708 <refclass>Macro</refclass>
711 <title>Syntax</title>
713 <function>deref-array</function> <replaceable>array type positon</replaceable> => <returnvalue>value</returnvalue>
717 <title>Arguments and Values</title>
720 <term><parameter>array</parameter></term>
722 <para>A foreign array.
727 <term><parameter>type</parameter></term>
729 <para>The foreign type of the array.
734 <term><parameter>position</parameter></term>
736 <para>An integer specifying the position to retrieve from
742 <term><returnvalue>value</returnvalue></term>
744 <para>The value stored in the position of the array.
751 <title>Description</title>
753 Dereferences (retrieves) the value of an array element.
757 <title>Examples</title>
760 (let ((fs (convert-to-foreign-string "ab")))
761 (values (null-char-p (deref-array fs 'ca 0))
762 (null-char-p (deref-array fs 'ca 2))))
768 <title>Side Effects</title>
772 <title>Affected by</title>
776 <title>Exceptional Situations</title>
783 <title>Objects</title>
785 <title>Overview</title>
787 Objects are entities that can allocated and freed.
792 <refentry id="allocate-foreign-object">
794 <refname>allocate-foreign-object</refname>
795 <refpurpose>Allocates an instance of a foreign object.
797 <refclass>Macro</refclass>
800 <title>Syntax</title>
802 <function>allocate-foreign-object</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
806 <title>Arguments and Values</title>
809 <term><parameter>type</parameter></term>
811 <para>A type of foreign object to allocate.
816 <term><returnvalue>ptr</returnvalue></term>
818 <para>A pointer to the foreign object.
825 <title>Description</title>
827 Allocates an instance of a foreign object. It returns a pointer to the object.
831 <title>Examples</title>
833 (def-struct ab (a :int) (b :double))
834 (allocate-foreign-object 'ab)
839 <title>Side Effects</title>
843 <title>Affected by</title>
847 <title>Exceptional Situations</title>
853 <refentry id="free-foreign-object">
855 <refname>free-foreign-object</refname>
856 <refpurpose>Frees memory that was allocated for a foreign boject.
858 <refclass>Macro</refclass>
861 <title>Syntax</title>
863 <function>free-foreign-object</function> <replaceable>ptr</replaceable>
867 <title>Arguments and Values</title>
870 <term><parameter>ptr</parameter></term>
872 <para>A pointer to the allocated foreign object to free.
879 <title>Description</title>
881 Frees the memory used by the allocation of a foreign object.
885 <title>Side Effects</title>
889 <title>Affected by</title>
893 <title>Exceptional Situations</title>
899 <refentry id="pointer-address">
901 <refname>pointer-address</refname>
902 <refpurpose>Returns the address of a pointer.
904 <refclass>Macro</refclass>
907 <title>Syntax</title>
909 <function>pointer-address</function> <replaceable>ptr</replaceable> => <returnvalue>address</returnvalue>
913 <title>Arguments and Values</title>
916 <term><parameter>ptr</parameter></term>
918 <para>A pointer to a foreign object.
923 <term><parameter>address</parameter></term>
925 <para>An integer representing the pointer's address.
932 <title>Description</title>
934 Returns the address as an integer of a pointer.
938 <title>Side Effects</title>
942 <title>Affected by</title>
946 <title>Exceptional Situations</title>
952 <refentry id="deref-pointer">
954 <refname>deref-pointer</refname>
955 <refpurpose>Deferences a pointer.
957 <refclass>Macro</refclass>
960 <title>Syntax</title>
962 <function>def-pointer</function> <replaceable>ptr type</replaceable> => <returnvalue>value</returnvalue>
966 <title>Arguments and Values</title>
969 <term><parameter>ptr</parameter></term>
971 <para>A pointer to a foreign object.
976 <term><parameter>type</parameter></term>
978 <para>A foreign type of the object being pointed to.
983 <term><parameter>value</parameter></term>
985 <para>The value of the object where the pointer points.
992 <title>Description</title>
994 Returns the object to which a pointer points.
998 <title>Examples</title>
1001 (let ((fs (convert-to-foreign-string "a")))
1003 (ensure-char (deref-pointer fs :char))
1004 (free-foreign-object fs)))
1010 <title>Side Effects</title>
1014 <title>Affected by</title>
1018 <title>Exceptional Situations</title>
1023 <refentry id="make-null-pointer">
1025 <refname>make-null-pointer</refname>
1026 <refpurpose>Create a &null; pointer.
1028 <refclass>Macro</refclass>
1031 <title>Syntax</title>
1033 <function>make-null-pointer</function> <replaceable>type</replaceable> => <returnvalue>ptr</returnvalue>
1037 <title>Arguments and Values</title>
1040 <term><parameter>type</parameter></term>
1042 <para>A type of object to which the pointer refers.
1047 <term><parameter>ptr</parameter></term>
1049 <para>The &null; pointer of type <parameter>type</parameter>.
1056 <title>Description</title>
1058 Creates a &null; pointer of a specified type.
1062 <title>Side Effects</title>
1066 <title>Affected by</title>
1070 <title>Exceptional Situations</title>
1076 <refentry id="null-pointer-p">
1078 <refname>null-pointer-p</refname>
1079 <refpurpose>Tests a pointer for &null; value.
1081 <refclass>Macro</refclass>
1084 <title>Syntax</title>
1086 <function>null-pointer-p</function> <replaceable>ptr</replaceable> => <returnvalue>is-null</returnvalue>
1090 <title>Arguments and Values</title>
1093 <term><parameter>ptr</parameter></term>
1095 <para>A foreign object pointer.
1100 <term><returnvalue>is-null</returnvalue></term>
1102 <para>The boolean flag.
1109 <title>Description</title>
1111 A predicate testing if a pointer is has a &null; value.
1115 <title>Side Effects</title>
1119 <title>Affected by</title>
1123 <title>Exceptional Situations</title>
1129 <refentry id="null-cstring-pointer">
1131 <refname>+null-cstring-pointer+</refname>
1132 <refpurpose>A constant &null; cstring pointer.
1134 <refclass>Constant</refclass>
1137 <title>Description</title>
1139 A &null; cstring pointer. This can be used for testing
1140 if a cstring returned by a function is &null;.
1148 <title>Strings</title>
1150 <title>Overview</title>
1152 &uffi; has functions to two types of <varname>C</varname>-compatible
1153 strings, <emphasis>cstring</emphasis> and <emphasis>foreign</emphasis> strings.
1154 cstrings are used as parameters to and from functions. An implementation, such as CMUCL,
1155 may not convert these to a foreign type for efficiency sake. Thus, it is not
1156 possible to "allocate" a cstring. In contrast, foreign strings
1157 always need to have memory for them.
1161 <refentry id="convert-from-cstring">
1163 <refname>convert-from-cstring</refname>
1164 <refpurpose>Converts a cstring to a Lisp string.
1166 <refclass>Macro</refclass>
1169 <title>Syntax</title>
1171 <function>convert-from-cstring</function> <replaceable>cstring</replaceable> => <returnvalue>string</returnvalue>
1175 <title>Arguments and Values</title>
1178 <term><parameter>cstring</parameter></term>
1185 <term><returnvalue>string</returnvalue></term>
1187 <para>A Lisp string.
1194 <title>Description</title>
1196 Converts a Lisp string to a <constant>cstring</constant>. This is
1197 most often used when processing the results of a foreign function
1198 that returns a cstring.
1202 <title>Side Effects</title>
1206 <title>Affected by</title>
1210 <title>Exceptional Situations</title>
1216 <refentry id="convert-to-cstring">
1218 <refname>convert-to-cstring</refname>
1219 <refpurpose>Converts a Lisp string to a cstring.
1221 <refclass>Macro</refclass>
1224 <title>Syntax</title>
1226 <function>convert-to-cstring</function> <replaceable>string</replaceable> => <returnvalue>cstring</returnvalue>
1230 <title>Arguments and Values</title>
1233 <term><parameter>string</parameter></term>
1235 <para>A Lisp string.
1240 <term><returnvalue>cstring</returnvalue></term>
1249 <title>Description</title>
1251 Converts a Lisp string to a
1252 <varname>cstring</varname>. The
1253 <varname>cstring</varname> should be freed with
1254 <function>free-cstring</function>.
1258 <title>Side Effects</title>
1262 <title>Affected by</title>
1266 <title>Exceptional Situations</title>
1272 <refentry id="free-cstring">
1274 <refname>free-cstring</refname>
1275 <refpurpose>Free memory used by cstring.
1277 <refclass>Macro</refclass>
1280 <title>Syntax</title>
1282 <function>free-cstring</function> <replaceable>cstring</replaceable>
1286 <title>Arguments and Values</title>
1289 <term><parameter>cstring</parameter></term>
1298 <title>Description</title>
1300 Frees any memory possibly allocated by
1301 <function>convert-to-cstring</function>.
1305 <title>Side Effects</title>
1309 <title>Affected by</title>
1313 <title>Exceptional Situations</title>
1319 <refentry id="with-cstring">
1321 <refname>with-cstring</refname>
1322 <refpurpose>Binds a newly created cstring.
1324 <refclass>Macro</refclass>
1327 <title>Syntax</title>
1329 <function>with-cstring</function> <replaceable>(cstring string) {body}</replaceable>
1333 <title>Arguments and Values</title>
1336 <term><parameter>cstring</parameter></term>
1338 <para>A symbol naming the cstring to be created.
1343 <term><parameter>string</parameter></term>
1345 <para>A Lisp string that will be translated to a cstring.
1350 <term><parameter>body</parameter></term>
1352 <para>The body of where the cstring will be bound.
1359 <title>Description</title>
1361 Binds a lexical variable to a newly allocated <varname>cstring</varname>. Automatically frees <varname>cstring</varname>.
1365 <title>Examples</title>
1368 (def-function ("getenv" c-getenv)
1370 :returning :cstring)
1373 "Returns an environment variable, or NIL if it does not exist"
1374 (check-type key string)
1375 (with-cstring (key-cstring key)
1376 (convert-from-cstring (c-getenv key-cstring))))
1381 <title>Side Effects</title>
1385 <title>Affected by</title>
1389 <title>Exceptional Situations</title>
1395 <refentry id="convert-from-foreign-string">
1397 <refname>convert-from-foreign-string</refname>
1398 <refpurpose>Converts a foreign string into a Lisp string.
1400 <refclass>Macro</refclass>
1403 <title>Syntax</title>
1405 <function>convert-from-foreign-string</function> <replaceable>foreign-string &key length null-terminated-p</replaceable> => <returnvalue>string</returnvalue>
1409 <title>Arguments and Values</title>
1412 <term><parameter>foreign-string</parameter></term>
1414 <para>A foreign string.
1419 <term><parameter>length</parameter></term>
1421 <para>The length of the foreign string to
1422 convert. The default is the length of the string until a &null;
1423 character is reached.
1428 <term><parameter>null-terminated-p</parameter></term>
1430 <para>A boolean flag with a default value of &t; When true,
1431 the string is converted until the first &null; character is reached.
1436 <term><returnvalue>string</returnvalue></term>
1438 <para>A Lisp string.
1445 <title>Description</title>
1447 Returns a Lisp string from a foreign string.
1448 Can translated ASCII and binary strings.
1452 <title>Side Effects</title>
1456 <title>Affected by</title>
1460 <title>Exceptional Situations</title>
1466 <refentry id="convert-to-foreign-string">
1468 <refname>convert-to-foreign-string</refname>
1469 <refpurpose>Converts a Lisp string to a foreign string.
1471 <refclass>Macro</refclass>
1474 <title>Syntax</title>
1476 <function>convert-to-foreign-string</function> <replaceable>string</replaceable> => <returnvalue>foreign-string</returnvalue>
1480 <title>Arguments and Values</title>
1483 <term><parameter>string</parameter></term>
1485 <para>A Lisp string.
1490 <term><returnvalue>foreign-string</returnvalue></term>
1492 <para>A foreign string.
1499 <title>Description</title>
1501 Converts a Lisp string to a foreign string. Memory should be
1502 freed with <function>free-foreign-object</function>.
1506 <title>Side Effects</title>
1510 <title>Affected by</title>
1514 <title>Exceptional Situations</title>
1521 <refentry id="allocate-foreign-string">
1523 <refname>allocate-foreign-string</refname>
1524 <refpurpose>Allocates space for a foreign string.
1526 <refclass>Macro</refclass>
1529 <title>Syntax</title>
1531 <function>allocate-foreign-string</function> <replaceable>size &key unsigned</replaceable> => <returnvalue>foreign-string</returnvalue>
1535 <title>Arguments and Values</title>
1538 <term><parameter>size</parameter></term>
1540 <para>The size of the space to be allocated in bytes.
1545 <term><parameter>unsigned</parameter></term>
1547 <para>A boolean flag with a default value of &t;. When true,
1548 marks the pointer as an <constant>:unsigned-char</constant>.
1553 <term><returnvalue>foreign-string</returnvalue></term>
1555 <para>A foreign string which has undefined contents.
1562 <title>Description</title>
1564 Allocates space for a foreign string. Memory should
1565 be freed with <function>free-foreign-object</function>.
1569 <title>Side Effects</title>
1573 <title>Affected by</title>
1577 <title>Exceptional Situations</title>
1585 <title>Functions & Libraries</title>
1587 <refentry id="def-function">
1589 <refname>def-function</refname>
1590 <refpurpose>Declares a function.
1592 <refclass>Macro</refclass>
1595 <title>Syntax</title>
1597 <function>def-function</function> <replaceable>name args &key module returning</replaceable>
1601 <title>Arguments and Values</title>
1604 <term><parameter>name</parameter></term>
1606 <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.
1611 <term><parameter>args</parameter></term>
1613 <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
1618 <term><parameter>module</parameter></term>
1620 <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
1624 <term><returnvalue>returning</returnvalue></term>
1626 <para>A declaration specifying the result type of the
1627 foreign function. If <constant>:void</constant> indicates module does not return any value.
1634 <title>Description</title>
1635 <para>Declares a foreign function.
1639 <title>Examples</title>
1641 (def-function "gethostname"
1648 <title>Side Effects</title>
1652 <title>Affected by</title>
1656 <title>Exceptional Situations</title>
1661 <refentry id="load-foreign-library">
1663 <refname>load-foreign-library</refname>
1664 <refpurpose>Loads a foreign library.
1666 <refclass>Function</refclass>
1669 <title>Syntax</title>
1671 <function>load-foreign-library</function> <replaceable>filename &key module supporting-libraries</replaceable> => <returnvalue>success</returnvalue>
1675 <title>Arguments and Values</title>
1678 <term><parameter>filename</parameter></term>
1680 <para>A string or pathname specifying the library location
1681 in the filesystem. At least one implementation (&lw;) can not
1682 accept a logical pathname.
1687 <term><parameter>module</parameter></term>
1689 <para>A string designating the name of the module to apply
1690 to functions in this library. (Required for Lispworks)
1695 <term><parameter>supporting-libraries</parameter></term>
1697 <para>A list of strings naming the libraries required to
1698 link the foreign library. (Required by CMUCL)
1703 <term><returnvalue>success</returnvalue></term>
1705 <para>A boolean flag, &t; if the library was able to be
1706 loaded successfully or if the library has been previously loaded,
1714 <title>Description</title>
1715 <para>Loads a foreign library. Applies a module name to functions
1716 within the library. Ensures that a library is only loaded once during
1721 <title>Examples</title>
1723 (load-foreign-library #p"/usr/lib/libmysqlclient.so"
1725 :supporting-libraries '("c"))
1730 <title>Side Effects</title>
1731 <para>Loads the foreign code into the Lisp system.
1735 <title>Affected by</title>
1736 <para>Ability to load the file.</para>
1739 <title>Exceptional Situations</title>