luasocket/doc/installation.html

164 lines
4.9 KiB
HTML
Raw Normal View History

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta name="description" content="LuaSocket: Introduction to the core">
<meta name="keywords" content="Lua, LuaSocket, TCP, UDP, Network, Support,
Installation">
2004-12-13 07:26:01 +01:00
<title>LuaSocket: Installation</title>
<link rel="stylesheet" href="reference.css" type="text/css">
</head>
<body>
<!-- header +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<div class=header>
<hr>
<center>
<table summary="LuaSocket logo">
<tr><td align=center><a href="http://www.lua.org">
<img width=128 height=128 border=0 alt="LuaSocket" src="luasocket.png">
</a></td></tr>
<tr><td align=center valign=top>Network support for the Lua language
</td></tr>
</table>
<p class=bar>
2009-05-27 11:31:38 +02:00
<a href="index.html">home</a> &middot;
<a href="index.html#download">download</a> &middot;
2004-12-13 07:26:01 +01:00
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
</p>
</center>
<hr>
</div>
2004-12-13 07:26:01 +01:00
<!-- installation ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<h2>Installation</h2>
2007-06-15 08:28:56 +02:00
<p> LuaSocket 2.0.2 uses the new package system for Lua 5.1.
All Lua library developers are encouraged to update their libraries so that
all libraries can coexist peacefully and users can benefit from the
standardization and flexibility of the standard.
</p>
<p>
2006-04-20 06:16:23 +02:00
Those stuck with Lua 5.0 will need the
<a href=http://www.keplerproject.org/compat/>compat-5.1</a>
2006-04-20 06:16:23 +02:00
module. It is maintained by
<a href=http://www.keplerproject.org/>The Kepler
Project</a>'s team, and implements the Lua 5.1 package proposal
on top of Lua 5.0. </p>
<p> Here we will only describe the standard distribution.
If the standard doesn't meet your needs, we refer you to the
Lua discussion list, where any question about the package
scheme will likely already have been answered. </p>
<h3>Directory structure</h3>
2005-09-29 08:11:42 +02:00
<p> On Unix systems, the standard distribution uses two base
directories, one for system dependent files, and another for system
2005-11-22 21:51:28 +01:00
independent files. Let's call these directories <tt>&lt;CDIR&gt;</tt>
and <tt>&lt;LDIR&gt;</tt>, respectively.
2005-09-29 08:11:42 +02:00
For instance, in my laptop, I use '<tt>/usr/local/lib/lua/5.0</tt>' for
2005-11-22 21:51:28 +01:00
<tt>&lt;CDIR&gt;</tt> and '<tt>/usr/local/share/lua/5.0</tt>' for
<tt>&lt;LDIR&gt;</tt>. On Windows, sometimes only one directory is used, say
2005-09-29 08:11:42 +02:00
'<tt>c:\program files\lua\5.0</tt>'. Here is the standard LuaSocket
distribution directory structure:</p>
<pre class=example>
2005-11-22 21:51:28 +01:00
&lt;LDIR&gt;/compat-5.1.lua
&lt;LDIR&gt;/ltn12.lua
&lt;LDIR&gt;/socket.lua
&lt;CDIR&gt;/socket/core.dll
&lt;LDIR&gt;/socket/http.lua
&lt;LDIR&gt;/socket/tp.lua
&lt;LDIR&gt;/socket/ftp.lua
&lt;LDIR&gt;/socket/smtp.lua
&lt;LDIR&gt;/socket/url.lua
&lt;LDIR&gt;/mime.lua
&lt;CDIR&gt;/mime/core.dll
</pre>
2005-08-12 07:56:32 +02:00
<p> Naturally, on Unix systems, <tt>core.dll</tt>
2006-04-20 06:16:23 +02:00
would be replaced by <tt>core.so</tt>.
2005-10-05 05:16:17 +02:00
</p>
<p> In order for the interpreter to find all LuaSocket components, three
environment variables need to be set. The first environment variable tells
the interpreter to load the <tt>compat-5.1.lua</tt> module at startup: </p>
<pre class=example>
2005-11-22 21:51:28 +01:00
LUA_INIT=@&lt;LDIR&gt;/compat-5.1.lua
</pre>
2006-04-20 06:16:23 +02:00
<p>
This is only need for Lua&nbsp;5.0! Lua&nbsp;5.1 comes with
the package system built in, of course.
2006-04-20 06:16:23 +02:00
</p>
2004-12-13 06:06:15 +01:00
<p>
The other two environment variables instruct the compatibility module to
2004-12-13 06:06:15 +01:00
look for dynamic libraries and extension modules in the appropriate
directories and with the appropriate filename extensions.
</p>
<pre class=example>
2005-11-22 21:51:28 +01:00
LUA_PATH=&lt;LDIR&gt;/?.lua;?.lua
LUA_CPATH=&lt;CDIR&gt;/?.dll;?.dll
</pre>
<p> Again, naturally, on Unix systems the shared library extension would be
2005-10-05 05:16:17 +02:00
<tt>.so</tt> instead of <tt>.dll</tt>.</p>
<h3>Using LuaSocket</h3>
<p> With the above setup, and an interpreter with shared library support,
it should be easy to use LuaSocket. Just fire the interpreter and use the
<tt>require</tt> function to gain access to whatever module you need:</p>
<pre class=example>
2007-06-15 08:28:56 +02:00
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
&gt; socket = require("socket")
2005-09-29 08:11:42 +02:00
&gt; print(socket._VERSION)
2007-06-15 08:28:56 +02:00
--&gt; LuaSocket 2.0.2
</pre>
<p> Each module loads their dependencies automatically, so you only need to
load the modules you directly depend upon: </p>
<pre class=example>
2007-06-15 08:28:56 +02:00
Lua 5.1.2 Copyright (C) 1994-2007 Lua.org, PUC-Rio
&gt; http = require("socket.http")
&gt; print(http.request("http://www.cs.princeton.edu/~diego/professional/luasocket"))
--&gt; homepage gets dumped to terminal
</pre>
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<div class=footer>
<hr>
<center>
<p class=bar>
2009-05-27 11:31:38 +02:00
<a href="index.html">home</a> &middot;
<a href="index.html#down">download</a> &middot;
2004-12-13 07:26:01 +01:00
<a href="installation.html">installation</a> &middot;
<a href="introduction.html">introduction</a> &middot;
<a href="reference.html">reference</a>
</p>
<p>
<small>
Last modified by Diego Nehab on <br>
Thu Apr 20 00:25:30 EDT 2006
</small>
</p>
</center>
</div>
</body>
</html>