Debian Codegraph @

doc/manual.html

raw ◀ ▶
1 Debian patch touch this file
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html>
4 <head>
5 <title>Lua XML-RPC: XML-RPC interface to the Lua programming language</title>
6 <link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
8 </head>
9 <body>
10
11 <div id="container">
12
13 <div id="product">
14 <div id="product_logo">
15 <a href="http://www.keplerproject.org">
16 <img alt="Lua XML-RPC logo" src="luaxmlrpc.png"/>
17 </a>
18 </div>
19 <div id="product_name"><big><strong>Lua XML-RPC</strong></big></div>
20 <div id="product_description">XML-RPC interface to the Lua programming language</div>
21 </div> <!-- id="product" -->
22
23 <div id="main">
24
25 <div id="navigation">
26 <h1>Lua XML-RPC</h1>
27 <ul>
28 <li><a href="index.html">Home</a>
29 <ul>
30 <li><a href="index.html#overview">Overview</a></li>
31 <li><a href="index.html#status">Status</a></li>
32 <li><a href="index.html#download">Download</a></li>
33 <li><a href="index.html#history">History</a></li>
34 <li><a href="index.html#credits">Credits</a></li>
35 <li><a href="index.html#contact">Contact</a></li>
36 </ul>
37 </li>
38 <li><strong>Manual</strong>
39 <ul>
40 <li><a href="manual.html#introduction">Introduction</a></li>
41 <li><a href="manual.html#installation">Installation</a></li>
42 <li><a href="manual.html#data_types">Data types</a></li>
43 <li><a href="manual.html#functions">Library functions</a></li>
44 <li><a href="manual.html#client">Client side</a></li>
45 <li><a href="manual.html#server">Server side</a></li>
46 <li><a href="manual.html#references">References</a></li>
47 </ul>
48 </li>
49 <li><a href="examples.html">Examples</a></li>
50 <li><a href="license.html">License</a></li>
51 </ul>
52 </div> <!-- id="navigation" -->
53
54 <div id="content">
55
56 <h2><a name="introduction"></a>Introduction</h2>
57
58 <p>Lua XML-RPC is a <a href="http://www.lua.org">Lua</a> library that can be used
59 to build <a href="http://www.xmlrpc.com">XML-RPC</a> clients and
60 servers. It enables a Lua program to:</p>
61
62 <ul>
63 <li>Encode and decode XML-RPC messages without handling XML code</li>
64 <li>Transform Lua data structures into XML-RPC data types and vice-versa</li>
65 </ul>
66
67 <p>Lua XML-RPC provides a simple API and an abstraction layer over XML avoiding
68 manipulation of string representation of data structures.</p>
69
70 <p>Lua XML-RPC is based on
71 <a href="http://www.keplerproject.org/luaexpat">LuaExpat</a> and on
72 <a href="http://www.lua.org">Lua 5.1</a>.
73 The abstraction layer over HTTP depends on
74 <a href="http://w3.impa.br/~diego/software/luasocket/">LuaSocket 2.0.2</a>.</p>
75
76 <h2><a name="installation"></a>Installation</h2>
77
78 <p>Lua XML-RPC is composed by three Lua files:
79
80 <dl>
81 <dt><code>init.lua</code></dt>
82 <dd>Main source file providing the API</dd>
83 <dt><code>http.lua</code></dt>
84 <dd>API to call XML-RPC via HTTP</dd>
85 <dt><code>server.lua</code></dt>
86 <dd>Server side API</dd>
87 </dl>
88 </p>
89
90 These files should be copied to a directory named <code>xmlrpc</code> created in your
91 <code>LUA_PATH</code>.</p>
92
93 <p>Lua XML-RPC follows the
94 <a href="http://www.keplerproject.org/compat/">package model</a>
95 for Lua 5.1, therefore it should be "installed". Refer to
96 <a href="http://www.keplerproject.org/compat/manual.html#configuration">
97 Compat-5.1 configuration</a> section about how to install the module.</p>
98
99 <h2><a name="data_types"></a>Data types</h2>
100
101 <p>XML-RPC elements are usually represented by the simplest
102 correspondent Lua object. When the correspondance is not obvious, a
103 Lua table is used with a field specifying the element.</p>
104
105 <h3><a name="xr2lua"></a>From XML-RPC to Lua</h3>
106
107 <p>When converting from XML-RPC element to a Lua data item or table,
108 a table with a field <code>tag</code> is used. The child elements are
109 stored at numbered indexes and white space is ignored.</p>
110
111 <table>
112 <tr>
113 <th>XML-RPC data type(s)</th>
114 <th>Lua object</th>
115 </tr>
116
117 <tr>
118 <td>
119 double<br />
120 int<br />
121 i4
122 </td>
123 <td>number</td>
124 </tr>
125
126 <tr>
127 <td>string</td>
128 <td>string</td>
129 </tr>
130
131 <tr>
132 <td>boolean</td>
133 <td>boolean</td>
134 </tr>
135
136 <tr>
137 <td>
138 struct<br />
139 arrray
140 </td>
141 <td>table</td>
142 </tr>
143
144 <tr>
145 <td>other elements</td>
146 <td>
147 <pre>{
148 tag = "element name",
149 [1] = &lt;first child&gt;,
150 [2] = &lt;second child&gt;,
151 [3] = ...,
152 }</pre>
153 </td>
154 </tr>
155 </table>
156
157
158 <h3><a name="lua2xr"></a>From Lua to XML-RPC</h3>
159
160 <p>A conversion from a Lua data item or table to an XML-RPC element
161 can be made automatically or explicitly. The automatic conversion rules
162 are:</p>
163
164 <table>
165 <tr>
166 <th>Lua object</th>
167 <th>XML-RPC data type</th>
168 </tr>
169
170 <tr>
171 <td>number</td>
172 <td>int or double</td>
173 </tr>
174
175 <tr>
176 <td>string</td>
177 <td>string</td>
178 </tr>
179
180 <tr>
181 <td>boolean</td>
182 <td>boolean</td>
183 </tr>
184
185 <tr>
186 <td><code>{ key = val }</code></td>
187 <td>
188 <pre>
189 &lt;struct&gt;
190 &lt;member&gt;
191 &lt;name&gt;key&lt;/name&gt;
192 &lt;value&gt;<em>val</em>&lt;/value&gt;
193 &lt;/member&gt;
194 &lt;/struct&gt;
195 </pre>
196 <small><em>val</em> is converted according to the same rules.</small>
197 </td>
198 </tr>
199 </table>
200
201 <p>Ifn case of a table that has numeric keys, the resulting struct will
202 have the string representation of these numbers as keys (e.g.
203 <code>"1"</code> instead of <code>1</code>). The library tries to
204 convert integral numbers to integer types, otherwise converting
205 them to floating point numbers.</p>
206
207 <h2><a name="functions"></a>Library functions</h2>
208
209 <p>The <code>xmlrpc.lua</code> file implements the functions that encode and decode XML-RPC messages and transform
210 data types between the Lua and XML-RPC. The functions are:</p>
211
212 <dl>
213 <dt><a name="clEncode"></a><strong><code>clEncode (method_name [, params]) =&gt; method_call</code></strong></dt>
214 <dd>Build a XML-RPC document containing a <code>methodCall</code>
215 element. It receives a string with the method's name and an
216 optional list of parameters. The result is a string containing the
217 XML-RPC document.</dd>
218
219 <dt><a name="clDecode"></a><strong><code>clDecode (method_response) =&gt; ok, results</code></strong></dt>
220 <dd>Disassemble the server response into a Lua object. It receives a
221 string containing the XML-RPC document representing the
222 <code>methodResponse</code> element. The result is a boolean
223 indicating wether the call was successful or not followed by the
224 resulting objects (typically a methodResponse has only one value so
225 only one Lua object will be returned). In case of error the
226 <code>false</code> value is followed by the XMLRPC
227 <em>faultString</em> and the <em>faultCode</em>. This values are
228 extracted from the <code>fault</code> element.</dd>
229
230 <dt><a name="srvDecode"></a><strong><code>srvDecode (method_call) =&gt; method_name, list_params</code></strong></dt>
231 <dd>Disassemble the client request into a method's name and a table
232 with the list of parameters. It receives a string containing the
233 XML-RPC document representing the <code>methodCall</code> element.
234 The result is a string with the name of the method to be called and
235 a Lua table with the arguments to the call.</dd>
236
237 <dt><a name="srvEncode"></a><strong><code>srvEncode (object, is_fault) =&gt; method_response</code></strong></dt>
238 <dd>Build a XML-RPC document containing a <code>methodResponse</code>
239 element. It receives a Lua object (a number, a string, a table, a
240 "created typed value" etc.) with the return value of the call. The
241 result is a string containing the XML-RPC document. Note that
242 XML-RPC defines that a response only returns <em>one</em> value so a
243 Lua function that returns more than one value has to <em>pack</em>
244 them into a table to guarantee that all of them will be returned.
245 The second parameter (<code>is_fault</code>) can be used to force a
246 <code>fault</code> element to be generated instead of a
247 <code>params</code>. In this case, the Lua object must be a table
248 with the members <code>faultCode</code> and
249 <code>faultString</code>.</dd>
250
251 <dt><a name="srvMethods"></a><strong><code>srvMethods (tab_or_func)</code></strong></dt>
252 <dd>Register the methods on the server. The parameter can be a table
253 or a dispatching function. If a <em>table</em> is given it can have
254 one level of objects with the corresponding methods. If a
255 <em>function</em> is given, it will replace the dispatcher.</dd>
256
257 <dt><a name="dispatch"></a><strong><code>dispatch (method_name) =&gt; function</code></strong></dt>
258 <dd>Returns a Lua function that implements the method call. Note that
259 the object is encapsulated into that function so that the call will
260 be turned into a real method call.</dd>
261 </dl>
262
263
264 <h2><a name="client"></a>Client side</h2>
265
266 <p>The <code>http.lua</code> file implements a simple
267 stand-alone client based on
268 <a href="http://w3.impa.br/~diego/software/luasocket/">LuaSocket 2.0.2</a>. The
269 following function is provided:</p>
270
271 <dl>
272 <dt><a name="call"></a><strong><code>call (url, method [, params])</code></strong></dt>
273 <dd>Execute the call to <code>method</code> at location
274 <code>url</code> with the given <code>params</code> (if any). The
275 <code>method</code> and <code>params</code> parameters will be just
276 passed to <a href="#clEncode">clEncode</a> function. The result is
277 the same as <a href="#clDecode">clDecode</a> function: a boolean
278 indicating whether the call was successful or not, followed by the
279 response value (if successful) or by the <em>faultString</em> and the
280 <em>faultCode</em> (if the call fails).</dd>
281 </dl>
282
283
284 <h2><a name="server"></a>Server side</h2>
285
286 <p>The distribution also offers a simple XML-RPC server implemented
287 over a CGI launcher. This launcher just have to offer a way to
288 decode POST data and to send data back to the client.</p>
289
290 <p>The <code>tests</code> directory contains a file named
291 <code>cgi.lua</code>, which implements an example of a simple XML-RPC
292 server using the package <code>post</code> (which parses incoming
293 POST data from the http server). An appropriate environment for
294 writing Lua functions is implemented; a new <code>assert</code>
295 function generates a XML-RPC fault in case of a false condition; a
296 <code>respond</code> function creates the correct header for the
297 responses. The main goal of <code>cgi.lua</code> is to give a
298 starting point for other implementations.</p>
299
300
301 <h2><a name="references"></a>References</h2>
302
303 <p>Related documentation can be found at: <a href="http://www.xmlrpc.com">http://www.xmlrpc.com</a>.</p>
304
305 </div> <!-- id="content" -->
306
307 </div> <!-- id="main" -->
308
309 <div id="about">
310 <p>
311 <a href="http://validator.w3.org/check?uri=referer">
•312 valid
313 </a>
314 </p>
315 </div> <!-- id="about" -->
316
317 </div> <!-- id="container" -->
318
319 </body>
320 </html>