499d11b9e5dcab65ee70531b01537dc9d8197bab
[uffi.git] / doc / ref_func_libr.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % myents SYSTEM "entities.inc">
5 %myents;
6 ]>
7
8 <reference id="func_libr">
9       <title>Functions &amp; Libraries</title>
10
11       <refentry id="def-function">
12         <refnamediv>
13           <refname>def-function</refname>
14         <refpurpose>Declares a function. 
15         </refpurpose>
16         <refclass>Macro</refclass>
17       </refnamediv>
18       <refsynopsisdiv>
19         <title>Syntax</title>
20         <synopsis>
21           <function>def-function</function> <replaceable>name args &amp;key module returning</replaceable>
22         </synopsis>
23       </refsynopsisdiv>
24       <refsect1>
25         <title>Arguments and Values</title>
26         <variablelist>
27           <varlistentry>
28             <term><parameter>name</parameter></term>
29             <listitem>
30               <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.
31               </para>
32             </listitem>
33           </varlistentry>
34           <varlistentry>
35             <term><parameter>args</parameter></term>
36             <listitem>
37               <para>A list of argument declarations. If &nil;, indicates that the function does not take any arguments.
38               </para>
39             </listitem>
40           </varlistentry>
41           <varlistentry>
42             <term><parameter>module</parameter></term>
43             <listitem>
44               <para>A string specifying which module (or library) that the foreign function resides. (Required by Lispworks)</para>
45             </listitem>
46           </varlistentry>
47           <varlistentry>
48             <term><returnvalue>returning</returnvalue></term>
49             <listitem>
50               <para>A declaration specifying the result type of the
51 foreign function. If <constant>:void</constant> indicates module does not return any value.
52               </para>
53             </listitem>
54           </varlistentry>
55         </variablelist>
56       </refsect1>
57       <refsect1>
58         <title>Description</title>
59         <para>Declares a foreign function.
60         </para>
61       </refsect1>
62       <refsect1>
63         <title>Examples</title>
64         <screen>
65 (def-function "gethostname" 
66   ((name (* :unsigned-char))
67    (len :int))
68   :returning :int)
69         </screen>
70       </refsect1>
71       <refsect1>
72         <title>Side Effects</title>
73         <para>None.</para>
74       </refsect1>
75       <refsect1>
76         <title>Affected by</title>
77         <para>None.</para>
78       </refsect1>
79       <refsect1>
80         <title>Exceptional Situations</title>
81         <para>None.</para>
82       </refsect1>
83     </refentry>
84
85       <refentry id="load-foreign-library">
86         <refnamediv>
87           <refname>load-foreign-library</refname>
88         <refpurpose>Loads a foreign library. 
89         </refpurpose>
90         <refclass>Function</refclass>
91       </refnamediv>
92       <refsect1>
93         <title>Syntax</title>
94 <synopsis>
95           <function>load-foreign-library</function> <replaceable>filename &amp;key module supporting-libraries force-load</replaceable> => <returnvalue>success</returnvalue>
96 </synopsis>
97       </refsect1>
98       <refsect1>
99         <title>Arguments and Values</title>
100         <variablelist>
101           <varlistentry>
102             <term><parameter>filename</parameter></term>
103             <listitem>
104               <para>A string or pathname specifying the library location
105 in the filesystem. At least one implementation (&lw;) can not
106 accept a logical pathname.  If this parameter denotes a pathname without a
107 directory component then most of the supported Lisp implementations will be
108 able to find the library themselves if it is located in one of the standard
109 locations as defined by the underlying operating system.
110               </para>
111             </listitem>
112           </varlistentry>
113           <varlistentry>
114             <term><parameter>module</parameter></term>
115             <listitem>
116               <para>A string designating the name of the module to apply
117 to functions in this library. (Required for Lispworks)
118               </para>
119             </listitem>
120           </varlistentry>
121           <varlistentry>
122             <term><parameter>supporting-libraries</parameter></term>
123             <listitem>
124               <para>A list of strings naming the libraries required to
125 link the foreign library. (Required by CMUCL)
126               </para>
127             </listitem>
128           </varlistentry>
129           <varlistentry>
130             <term><parameter>force-load</parameter></term>
131             <listitem>
132               <para>Forces the loading of the library if it has been previously loaded. 
133               </para>
134             </listitem>
135           </varlistentry>
136           <varlistentry>
137             <term><returnvalue>success</returnvalue></term>
138             <listitem>
139               <para>A boolean flag, &t; if the library was able to be
140 loaded successfully or if the library has been previously loaded,
141 otherwise &nil;.
142               </para>
143             </listitem>
144           </varlistentry>
145         </variablelist>
146       </refsect1>
147       <refsect1>
148         <title>Description</title>
149         <para>Loads a foreign library. Applies a module name to functions
150 within the library. Ensures that a library is only loaded once during
151 a session. A library can be reloaded by using the <symbol>:force-load</symbol> key.
152         </para>
153       </refsect1>
154       <refsect1>
155         <title>Examples</title>
156         <screen>
157   (load-foreign-library #p"/usr/lib/libmysqlclient.so" 
158                         :module "mysql" 
159                         :supporting-libraries '("c"))
160     => T
161         </screen>
162       </refsect1>
163       <refsect1>
164         <title>Side Effects</title>
165         <para>Loads the foreign code into the Lisp system.
166         </para>
167       </refsect1>
168       <refsect1>
169         <title>Affected by</title>
170         <para>Ability to load the file.</para>
171       </refsect1>
172       <refsect1>
173         <title>Exceptional Situations</title>
174         <para>None.</para>
175       </refsect1>
176     </refentry>
177
178       <refentry id="find-foreign-library">
179         <refnamediv>
180           <refname>find-foreign-library</refname>
181         <refpurpose>Finds a foreign library file.
182         </refpurpose>
183         <refclass>Function</refclass>
184       </refnamediv>
185       <refsect1>
186         <title>Syntax</title>
187 <synopsis>
188           <function>find-foreign-library</function> <replaceable>names directories &amp; drive-letters types</replaceable> => <returnvalue>path</returnvalue>
189 </synopsis>
190       </refsect1>
191       <refsect1>
192         <title>Arguments and Values</title>
193         <variablelist>
194           <varlistentry>
195             <term><parameter>names</parameter></term>
196             <listitem>
197               <para>A string or list of strings containing the base name of the library file.
198               </para>
199             </listitem>
200           </varlistentry>
201           <varlistentry>
202             <term><parameter>directories</parameter></term>
203             <listitem>
204               <para>A string or list of strings containing the directory the library file.
205               </para>
206             </listitem>
207           </varlistentry>
208           <varlistentry>
209             <term><parameter>drive-letters</parameter></term>
210             <listitem>
211               <para>A string or list of strings containing the drive letters for the library file.
212               </para>
213             </listitem>
214           </varlistentry>
215           <varlistentry>
216             <term><parameter>types</parameter></term>
217             <listitem>
218               <para>A string or list of strings containing the file type of the library file. Default
219 is &nil;. If &nil;, will use a default type based on the currently running implementation.
220               </para>
221             </listitem>
222           </varlistentry>
223           <varlistentry>
224             <term><returnvalue>path</returnvalue></term>
225             <listitem>
226               <para>A path containing the path found, or &nil; if the library file was not found.
227               </para>
228             </listitem>
229           </varlistentry>
230         </variablelist>
231       </refsect1>
232       <refsect1>
233         <title>Description</title>
234         <para>Finds a foreign library by searching through a number of possible locations. Returns
235 the path of the first found file.
236         </para>
237       </refsect1>
238       <refsect1>
239         <title>Examples</title>
240         <screen>
241 (find-foreign-library '("libmysqlclient" "libmysql")
242     '("/opt/mysql/lib/mysql/" "/usr/local/lib/" "/usr/lib/" "/mysql/lib/opt/")
243     :types '("so" "dll")
244     :drive-letters '("C" "D" "E"))
245 => #P"D:\\mysql\\lib\\opt\\libmysql.dll"
246         </screen>
247       </refsect1>
248       <refsect1>
249         <title>Side Effects</title>
250         <para>None.
251         </para>
252       </refsect1>
253       <refsect1>
254         <title>Affected by</title>
255         <para>None.</para>
256       </refsect1>
257       <refsect1>
258         <title>Exceptional Situations</title>
259         <para>None.</para>
260       </refsect1>
261     </refentry>
262
263 </reference>
264
265