Working on the manual.

This commit is contained in:
Diego Nehab 2005-06-14 04:29:23 +00:00
parent 8b114f3bf4
commit 65c35845c5
19 changed files with 91 additions and 91 deletions

15
FIX
View File

@ -1,13 +1,16 @@
url.absolute was not working when base_url was already parsed url.absolute was not working when base_url was already parsed
http.request was redirecting even when the location header is empty http.request was redirecting even when the location header was empty
tcp{client}:shutdown() was checking for group instead of class. tcp{client}:shutdown() was checking for group instead of class.
tcp{client}:send() now returns i+sent-1... tcp{client}:send() now returns i+sent-1...
get rid of a = socket.try() in the manual, except for protected cases. get rid of a = socket.try() in the manual, except for protected cases. replace it with assert.
replace it with assert. get rid of "base." kludge in package.loaded
get rid of "base." kludge
check all "require("http")" etc in the manual. check all "require("http")" etc in the manual.
make sure sock_gethostname.* only return success if the hp is not null! make sure sock_gethostname.* only return success if the hp is not null!
change 'l' prefix in C libraries to 'c' change 'l' prefix in C libraries to 'c' to avoid clash with LHF libraries
don't forget the declarations in luasocket.h and mime.h!!! don't forget the declarations in luasocket.h and mime.h!!!
setpeername was using udp{unconnected} setpeername was using udp{unconnected}
fixed a bug in http.lua that caused some requests to fail fixed a bug in http.lua that caused some requests to fail (Florian Berger)
fixed a bug in select.c that prevented sockets with descriptor 0 from working (Renato Maia)
fixed a "bug" that caused dns.toip to crash under uLinux
fixed a "bug" that caused a crash in gethostbyname under VMS
DEBUG and VERSION became _DEBUG and _VERSION

3
TODO
View File

@ -1,4 +1,3 @@
talk about the non-blocking connect in the manual talk about the non-blocking connect in the manual
test it on Windows!!! test it on Windows!!!
@ -13,7 +12,6 @@ functions for non-blocking so they can be used in the context of the
dispatcher! dispatcher!
adjust manual for new sock:send returns. adjust manual for new sock:send returns.
_VERSION, _DEBUG, etc.
leave code for losers that don't have nanosleep leave code for losers that don't have nanosleep
@ -42,3 +40,4 @@ testar os options!
eliminate globals from namespaces created by module(). eliminate globals from namespaces created by module().
* BUG NO SET DO TINYIRC!!! SINISTRO. * BUG NO SET DO TINYIRC!!! SINISTRO.
* _VERSION, _DEBUG, etc.

View File

@ -93,38 +93,24 @@ Windows XP, Linux, and Mac OS X.
</p> </p>
<p> <p>
The library can be downloaded in source code from the following links: The library can be downloaded in source code from the
</p> <a href=http://luaforge.net/projects/luasocket/>LuaSocket
project page</a> at LuaForge.
<blockquote>
<p>
<a href="luasocket-2.0.tar.gz">luasocket-2.0.tar.gz</a> <br>
<a href="luasocket-2.0.zip">luasocket-2.0.zip</a>
</p>
</blockquote>
<p>
Besides the full C and Lua source code for the library, the distribution Besides the full C and Lua source code for the library, the distribution
contains several examples, this user's manual and basic test procedures. contains several examples, this user's manual and basic test procedures.
</p> </p>
<p> <p>
I am also providing PC Win32 binaries for those that want to give Danilo Tuler is mantaining Win32 binaries for LuaSocket, which are also
LuaSocket a try (those on Unix or Mac OS X can just type <tt>make</tt>). available from LuaForge. These are compatible with the
These are compatible with the
<a href=http://luaforge.net/projects/luabinaries>LuaBinaries</a> <a href=http://luaforge.net/projects/luabinaries>LuaBinaries</a>
available from LuaForge. available from LuaForge.
</p> </p>
<blockquote>
<p> <p>
<a href="luasocket-2.0-win32.zip">luasocket-2.0-win32.zip</a> For those that want to give LuaSocket a quick try, download the
</p> stand-alone archive and unpack everything into
</blockquote> a directory, say <tt>c:\luasocket</tt>. Then set <tt>LUA_INIT</tt> to load
<p>
The quick and dirty way to use these binaries is to unpack everything into
a directory, say <tt>c:\luasocket</tt>, then set <tt>LUA_INIT</tt> to load
the <tt>compat-5.1.lua</tt> and set <tt>LUA_PATH</tt> and the <tt>compat-5.1.lua</tt> and set <tt>LUA_PATH</tt> and
<tt>LUA_CPATH</tt> to look for files in the current directory: <tt>LUA_CPATH</tt> to look for files in the current directory:
</p> </p>
@ -142,10 +128,10 @@ do the following:
</p> </p>
<pre class=example> <pre class=example>
c:\luasocket\&gt; lua c:\luasocket\&gt; lua50
Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio Lua 5.0.2 Copyright (C) 1994-2004 Tecgraf, PUC-Rio
&gt; http = require"socket.http" &gt; http = require"socket.http"
&gt; print(http.request"http://www.tecgraf.puc-rio.br/luasocket/") &gt; print(http.request"http://www.cs.princeton.edu/~diego/professional/luasocket/")
--&gt; the source to this web page gets dumped to terminal --&gt; the source to this web page gets dumped to terminal
</pre> </pre>
@ -173,31 +159,39 @@ has been helping a lot too! Thanks to you all!
<h2 id=new>What's New</h2> <h2 id=new>What's New</h2>
<p> <p>
The big change for the 2.0 (beta3) release was the adoption of the Lua 5.1 There is no big change for the 2.0 (final) release. It is basically a
package proposal. Naturally, there were a few bug fixes (a beta is a bug fix release. The only improvement is in the non-blocking
beta, is a beta). support.
</p> </p>
<ul> <ul>
<li> New compat-5.1 distribution: <li> Improved: <tt>tcp{client}:send(data, i)</tt> now returns <tt>(i+sent-1)</tt>. This is great for non-blocking I/O, but might break some code;
<ul> <li> Improved: HTTP, SMTP, and FTP functions accept a new field
<li> Installation uses new directory structure; <tt>connect</tt> that can be used to replace the function invoked to
<li> Namespace hierarchy is in now back in use (ex. <tt>socket.url</tt> create and connect the sockets used internally;
instead of <tt>url</tt>); <li> Fixed: <tt>url.absolute()</tt> was not working when <tt>base_url</tt> was
<li> All modules call <tt>require</tt> even for standard libraries; already parsed;
</ul> <li> Fixed: <tt>http.request()</tt> was redirecting even when the location
<li> <tt>socket.select</tt> wasn't calling <tt>tm_markstart</tt>; header was empty (well, it shouldn't be empty);
<li> LTN12 avoids coroutines (so you can go wild on the C side); <li> Fixed: <tt>tcp{client}:shutdown()</tt> was checking for group instead of class;
<li> Kludge on wsocket.c:sock_send for windows timeout issue <li> Fixed: <tt>socket.try()</tt> can't be used in place of <tt>assert()</tt>. The manual and examples don't do it anymore;
moved to buffer.c:sendraw so it's not a kludge anymore; <li> Improved: Get rid of <tt>require("base")</tt> kludge in <tt>package.loaded</tt>;
<li> <tt>socket.protect </tt>only catches errors thrown by <tt>socket.try</tt>; <li> Fixedd: Parts of the manual referred to <tt>require("http")</tt> instead of
<li> Fixed <tt>udp:sendto</tt> to call <tt>sock_sendto</tt> instead of <tt>require("socket.http")</tt>;
<tt>sock_send</tt>; <li> Improved: Changed 'l' prefix in C libraries to 'c' to avoid clash with LHF
<li> <tt>close</tt> wasn't returning 1! libraries;
<li> <tt>socket.gettime</tt> returns time since Unix Epoch 1/1/1970 (UTC); <li> Improved: Using bundles in Mac OS X;
<li> <tt>socket.sleep</tt> is robust to interrupts; <li> Fixed: <tt>luasocket.h</tt> was exporting <tt>luaopen_socket</tt>
<li> <tt>http.PROXY</tt> wasn't working; instead of <tt>luaopen_csocket</tt>;
<li> <tt>url.escape</tt> escapes only dangerous characters. <li> Fixed: <tt>udp:setpeername()</tt> only worked for
<tt>udp{unconnected}</tt>. Now you can "disconnect" an <tt>UDP</tt> socket;
<li> Fixed: bug in http.lua that caused some requests to fail (Florian
Berger);
<li> Fixed: bug in <tt>select.c</tt> that prevented sockets with descriptor 0 from working (Renato Maia);
<li> Fixed: "bug" that caused <tt>dns.toip</tt> to crash under uLinux;
<li> Fixed: "bug" that caused a crash in <tt>gethostbyname</tt> under VMS
(Renato Maia);
<li> Improved: <tt>socket.DEBUG</tt> and <tt>socket.VERSION</tt> became <tt>socket._DEBUGs</tt> and <tt>socket._VERSION</tt> for uniformity with other libraries.
</ul> </ul>
<!-- incompatible +++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- incompatible +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
@ -205,9 +199,11 @@ beta, is a beta).
<h3 id=incompatible>Incompatibilities with previous versions</h3> <h3 id=incompatible>Incompatibilities with previous versions</h3>
<ul> <ul>
<li> Namespaces are hierarchical again. This means that whoever used to <li> If you use the return value of <tt>tcp:send()</tt> <em>and</em> you
call <tt>require("url")</tt> should update their code to use the extra parameters to select only part of the string to be sent, your
<tt>require("socket.url")</tt>. code is now broken, but when you fix it, it will be much simpler;
<li> If you check <tt>socket.DEBUG</tt> or <tt>socket.VERSION</tt>,
change it to <tt>socket._DEBUG</tt> or <tt>socket._VERSION</tt>.
</ul> </ul>
<!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->

View File

@ -142,7 +142,7 @@ Support, Manual">
<blockquote> <blockquote>
<a href="socket.html">Socket</a> <a href="socket.html">Socket</a>
<blockquote> <blockquote>
<a href="socket.html#debug">DEBUG</a>, <a href="socket.html#_debug">_DEBUG</a>,
<a href="dns.html#dns">dns</a>, <a href="dns.html#dns">dns</a>,
<a href="socket.html#gettime">gettime</a>, <a href="socket.html#gettime">gettime</a>,
<a href="socket.html#newtry">newtry</a>, <a href="socket.html#newtry">newtry</a>,
@ -155,7 +155,7 @@ Support, Manual">
<a href="tcp.html#tcp">tcp</a>, <a href="tcp.html#tcp">tcp</a>,
<a href="socket.html#try">try</a>, <a href="socket.html#try">try</a>,
<a href="udp.html#udp">udp</a>, <a href="udp.html#udp">udp</a>,
<a href="socket.html#version">VERSION</a>. <a href="socket.html#_version">_VERSION</a>.
</blockquote> </blockquote>
</blockquote> </blockquote>

View File

@ -85,8 +85,8 @@ the user can also specify the local address and port to bind
<!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- debug ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=debug> <p class=name id=_debug>
socket.<b>DEBUG</b> socket.<b>_DEBUG</b>
</p> </p>
<p class=description> <p class=description>
@ -372,8 +372,8 @@ c = socket.try(socket.connect("localhost", 80))
<!-- version ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> <!-- version ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<p class=name id=version> <p class=name id=_version>
socket.<b>VERSION</b> socket.<b>_VERSION</b>
</p> </p>
<p class=description> <p class=description>

View File

@ -8,7 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Load required modules -- Load required modules
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local base = require("base") local base = _G
local string = require("string") local string = require("string")
local table = require("table") local table = require("table")
local socket = require("socket") local socket = require("socket")

View File

@ -10,7 +10,7 @@
]] ]]
-- make sure LuaSocket is loaded -- make sure LuaSocket is loaded
local io = require("io") local io = require("io")
local base = require("base") local base = _G
local string = require("string") local string = require("string")
local socket = require("socket") local socket = require("socket")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")

View File

@ -8,7 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Load required files -- Load required files
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local base = require("base") local base = _G
local table = require("table") local table = require("table")
local math = require("math") local math = require("math")
local string = require("string") local string = require("string")

View File

@ -8,7 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Declare module and import dependencies -- Declare module and import dependencies
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local base = require("base") local base = _G
local table = require("table") local table = require("table")
local string = require("string") local string = require("string")
local math = require("math") local math = require("math")

View File

@ -13,7 +13,7 @@ local url = require("socket.url")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")
local mime = require("mime") local mime = require("mime")
local string = require("string") local string = require("string")
local base = require("base") local base = _G
local table = require("table") local table = require("table")
module("socket.http") module("socket.http")
@ -25,7 +25,7 @@ TIMEOUT = 60
-- default port for document retrieval -- default port for document retrieval
PORT = 80 PORT = 80
-- user agent field sent in request -- user agent field sent in request
USERAGENT = socket.VERSION USERAGENT = socket._VERSION
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Extra sources and sinks -- Extra sources and sinks

View File

@ -172,22 +172,26 @@ static void inet_pushresolved(lua_State *L, struct hostent *hp)
i = 1; i = 1;
alias = hp->h_aliases; alias = hp->h_aliases;
lua_newtable(L); lua_newtable(L);
if (alias) {
while (*alias) { while (*alias) {
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_pushstring(L, *alias); lua_pushstring(L, *alias);
lua_settable(L, -3); lua_settable(L, -3);
i++; alias++; i++; alias++;
} }
}
lua_settable(L, resolved); lua_settable(L, resolved);
i = 1; i = 1;
lua_newtable(L); lua_newtable(L);
addr = (struct in_addr **) hp->h_addr_list; addr = (struct in_addr **) hp->h_addr_list;
if (addr) {
while (*addr) { while (*addr) {
lua_pushnumber(L, i); lua_pushnumber(L, i);
lua_pushstring(L, inet_ntoa(**addr)); lua_pushstring(L, inet_ntoa(**addr));
lua_settable(L, -3); lua_settable(L, -3);
i++; addr++; i++; addr++;
} }
}
lua_settable(L, resolved); lua_settable(L, resolved);
} }

View File

@ -10,7 +10,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local string = require("string") local string = require("string")
local table = require("table") local table = require("table")
local base = require("base") local base = _G
module("ltn12") module("ltn12")
filter = {} filter = {}

View File

@ -89,12 +89,12 @@ static int base_open(lua_State *L) {
/* export functions (and leave namespace table on top of stack) */ /* export functions (and leave namespace table on top of stack) */
luaL_openlib(L, "socket", func, 0); luaL_openlib(L, "socket", func, 0);
#ifdef LUASOCKET_DEBUG #ifdef LUASOCKET_DEBUG
lua_pushstring(L, "DEBUG"); lua_pushstring(L, "_DEBUG");
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
lua_rawset(L, -3); lua_rawset(L, -3);
#endif #endif
/* make version string available to scripts */ /* make version string available to scripts */
lua_pushstring(L, "VERSION"); lua_pushstring(L, "_VERSION");
lua_pushstring(L, LUASOCKET_VERSION); lua_pushstring(L, LUASOCKET_VERSION);
lua_rawset(L, -3); lua_rawset(L, -3);
return 1; return 1;

View File

@ -8,8 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Declare module and import dependencies -- Declare module and import dependencies
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
package.loaded.base = _G local base = _G
local base = require("base")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")
local mime = require("cmime") local mime = require("cmime")
module("mime") module("mime")

View File

@ -8,7 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Declare module and import dependencies -- Declare module and import dependencies
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local base = require("base") local base = _G
local coroutine = require("coroutine") local coroutine = require("coroutine")
local string = require("string") local string = require("string")
local math = require("math") local math = require("math")
@ -216,7 +216,7 @@ local function adjust_headers(mesgt)
end end
lower["date"] = lower["date"] or lower["date"] = lower["date"] or
os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
lower["x-mailer"] = lower["x-mailer"] or socket.VERSION lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
-- this can't be overriden -- this can't be overriden
lower["mime-version"] = "1.0" lower["mime-version"] = "1.0"
mesgt.headers = lower mesgt.headers = lower

View File

@ -7,8 +7,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Declare module and import dependencies -- Declare module and import dependencies
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
package.loaded.base = _G local base = _G
local base = require("base")
local string = require("string") local string = require("string")
local math = require("math") local math = require("math")
local socket = require("csocket") local socket = require("csocket")

View File

@ -8,7 +8,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- Declare module and import dependencies -- Declare module and import dependencies
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local base = require("base") local base = _G
local string = require("string") local string = require("string")
local socket = require("socket") local socket = require("socket")
local ltn12 = require("ltn12") local ltn12 = require("ltn12")

View File

@ -9,7 +9,7 @@
-- Declare module -- Declare module
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
local string = require("string") local string = require("string")
local base = require("base") local base = _G
local table = require("table") local table = require("table")
module("socket.url") module("socket.url")

View File

@ -69,7 +69,7 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone)
end end
end end
if not socket.DEBUG then if not socket._DEBUG then
fail("Please define LUASOCKET_DEBUG and recompile LuaSocket") fail("Please define LUASOCKET_DEBUG and recompile LuaSocket")
end end