2004-11-28 09:17:16 +01:00
|
|
|
<!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>
|
2004-11-28 09:17:16 +01:00
|
|
|
<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>
|
|
|
|
<a href="home.html">home</a> ·
|
|
|
|
<a href="home.html#download">download</a> ·
|
2004-12-13 07:26:01 +01:00
|
|
|
<a href="installation.html">installation</a> ·
|
2004-11-28 09:17:16 +01:00
|
|
|
<a href="introduction.html">introduction</a> ·
|
|
|
|
<a href="reference.html">reference</a>
|
|
|
|
</p>
|
|
|
|
</center>
|
|
|
|
<hr>
|
|
|
|
</div>
|
|
|
|
|
2004-12-13 07:26:01 +01:00
|
|
|
<!-- installation ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<h2>Instalation</h2>
|
|
|
|
|
2004-11-29 07:55:47 +01:00
|
|
|
<p> LuaSocket 2.0 uses the new package proposal 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>
|
|
|
|
The proposal was considered important enough by some of us to justify
|
|
|
|
early adoption, even before release of Lua 5.1.
|
|
|
|
Thus, a compability module
|
|
|
|
<a href=http://www.keplerproject.org/compat/>compat-5.1</a>
|
|
|
|
has been released in conjunction with Roberto Ierusalimschy and <a
|
2004-12-13 07:26:01 +01:00
|
|
|
href=http://www.keplerproject.org/>The Kepler Project</a> team.
|
2004-11-29 07:55:47 +01:00
|
|
|
It implements the Lua 5.1 package proposal on top of Lua 5.0. </p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<p> As far as LuaSocket is concerned, this means that whoever is
|
2004-11-29 07:55:47 +01:00
|
|
|
deploying a non-standard distribution of LuaSocket will probably
|
|
|
|
have no problems customizing it. 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.
|
2004-11-28 09:17:16 +01:00
|
|
|
</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
|
|
|
|
independent files. Let's call these directories <tt><LIB></tt>
|
|
|
|
and <tt><SHARE></tt>, respectively.
|
|
|
|
For instance, in my laptop, I use '<tt>/usr/local/lib/lua/5.0</tt>' for
|
|
|
|
<tt><LIB></tt> and '<tt>/usr/local/share/lua/5.0</tt>' for
|
|
|
|
<tt><SHARE></tt>. On Windows, only one directory is used, say
|
|
|
|
'<tt>c:\program files\lua\5.0</tt>'. Here is the standard LuaSocket
|
|
|
|
distribution directory structure:</p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<pre class=example>
|
2005-09-29 08:11:42 +02:00
|
|
|
<SHARE>/compat-5.1.lua
|
|
|
|
<SHARE>/ltn12.lua
|
2005-10-05 05:16:17 +02:00
|
|
|
<SHARE>/mime/init.lua (originally mime.lua)
|
2005-09-29 08:11:42 +02:00
|
|
|
<LIB>/mime/core.dll
|
2005-10-05 05:16:17 +02:00
|
|
|
<SHARE>/socket/init.lua (originally socket.lua)
|
2005-09-29 08:11:42 +02:00
|
|
|
<LIB>/socket/core.dll
|
|
|
|
<SHARE>/socket/http.lua
|
|
|
|
<SHARE>/socket/tp.lua
|
|
|
|
<SHARE>/socket/ftp.lua
|
|
|
|
<SHARE>/socket/smtp.lua
|
|
|
|
<SHARE>/socket/url.lua
|
2004-11-28 09:17:16 +01:00
|
|
|
</pre>
|
|
|
|
|
2005-08-12 07:56:32 +02:00
|
|
|
<p> Naturally, on Unix systems, <tt>core.dll</tt>
|
2005-10-05 05:16:17 +02:00
|
|
|
would be replaced by <tt>core.so</tt>. Notice that in the instalation,
|
|
|
|
<tt>socket.lua</tt> becomes <tt>socket/init.lua</tt>, and the same happens
|
|
|
|
with <tt>mime.lua</tt>, which becomes <tt>mime/init.lua</tt>.
|
|
|
|
</p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<p> In order for the interpreter to find all LuaSocket components, three
|
|
|
|
environment variables need to be set. The first environment variable tells
|
2004-11-29 07:55:47 +01:00
|
|
|
the interpreter to load the <tt>compat-5.1.lua</tt> module at startup: </p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<pre class=example>
|
2005-09-29 08:11:42 +02:00
|
|
|
LUA_INIT=@<SHARE>/compat-5.1.lua
|
2004-11-28 09:17:16 +01:00
|
|
|
</pre>
|
|
|
|
|
2004-12-13 06:06:15 +01:00
|
|
|
<p>
|
2004-11-28 09:17:16 +01:00
|
|
|
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>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<pre class=example>
|
2005-09-29 08:11:42 +02:00
|
|
|
LUA_PATH=<SHARE>/?.lua;?.lua
|
|
|
|
LUA_CPATH=<LIB>/?.dll;?.dll
|
2004-11-28 09:17:16 +01:00
|
|
|
</pre>
|
|
|
|
|
2005-09-29 08:11:42 +02:00
|
|
|
<p> Again, naturally, on Unix systmems the shared library extension would be
|
2005-10-05 05:16:17 +02:00
|
|
|
<tt>.so</tt> instead of <tt>.dll</tt>.</p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<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>
|
|
|
|
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
|
|
|
|
> socket = require("socket")
|
2005-09-29 08:11:42 +02:00
|
|
|
> print(socket._VERSION)
|
|
|
|
--> LuaSocket 2.0
|
2004-11-28 09:17:16 +01:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p> Each module loads their dependencies automatically, so you only need to
|
2004-11-29 07:55:47 +01:00
|
|
|
load the modues you directly depend upon: <p>
|
2004-11-28 09:17:16 +01:00
|
|
|
|
|
|
|
<pre class=example>
|
|
|
|
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
|
|
|
|
> http = require("socket.http")
|
2005-09-29 08:11:42 +02:00
|
|
|
>
|
|
|
|
print(http.request("http://www.cs.princeton.edu/~diego/professional/luasocket"))
|
2004-11-28 09:17:16 +01:00
|
|
|
--> homepage gets dumped to terminal
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<!-- footer +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
|
|
|
|
|
|
|
<div class=footer>
|
|
|
|
<hr>
|
|
|
|
<center>
|
|
|
|
<p class=bar>
|
|
|
|
<a href="home.html">home</a> ·
|
|
|
|
<a href="home.html#down">download</a> ·
|
2004-12-13 07:26:01 +01:00
|
|
|
<a href="installation.html">installation</a> ·
|
2004-11-28 09:17:16 +01:00
|
|
|
<a href="introduction.html">introduction</a> ·
|
|
|
|
<a href="reference.html">reference</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<small>
|
|
|
|
Last modified by Diego Nehab on <br>
|
2004-11-28 09:20:11 +01:00
|
|
|
Sun Nov 28 03:19:00 EST 2004
|
2004-11-28 09:17:16 +01:00
|
|
|
</small>
|
|
|
|
</p>
|
|
|
|
</center>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|