diff --git a/makefile.dist b/makefile.dist index a0a9313..267709f 100644 --- a/makefile.dist +++ b/makefile.dist @@ -2,7 +2,7 @@ # Distribution makefile #-------------------------------------------------------------------------- -DIST = luasocket-2.0-beta2 +DIST = luasocket-2.0-beta3 LUA = \ ftp.lua \ diff --git a/src/ftp.lua b/src/ftp.lua index 4e2bb62..43c62c2 100644 --- a/src/ftp.lua +++ b/src/ftp.lua @@ -6,12 +6,15 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load required modules +-- Declare module and import dependencies ----------------------------------------------------------------------------- local socket = require("socket") +local url = require("socket.url") +local tp = require("socket.tp") + local ltn12 = require("ltn12") -local url = require("url") -local tp = require("tp") + +module("socket.ftp") ----------------------------------------------------------------------------- -- Program constants diff --git a/src/http.lua b/src/http.lua index cdb435d..8ea4c47 100644 --- a/src/http.lua +++ b/src/http.lua @@ -6,12 +6,14 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load required modules +-- Declare module and import dependencies ------------------------------------------------------------------------------- local socket = require("socket") +local url = require("socket.url") local ltn12 = require("ltn12") local mime = require("mime") -local url = require("url") + +module("socket.http") ----------------------------------------------------------------------------- -- Program constants diff --git a/src/ltn12.lua b/src/ltn12.lua index 4fabb7d..993d3c3 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua @@ -5,6 +5,11 @@ -- RCS ID: $Id$ ----------------------------------------------------------------------------- +----------------------------------------------------------------------------- +-- Declare module +----------------------------------------------------------------------------- +module("ltn12") + filter = {} source = {} sink = {} diff --git a/src/luasocket.c b/src/luasocket.c index 735235a..ebe9f5f 100644 --- a/src/luasocket.c +++ b/src/luasocket.c @@ -19,6 +19,7 @@ \*=========================================================================*/ #include #include +#include /*=========================================================================*\ * LuaSocket includes @@ -85,9 +86,8 @@ static int global_unload(lua_State *L) { \*-------------------------------------------------------------------------*/ static int base_open(lua_State *L) { if (sock_open()) { - /* whoever is loading the library replaced the global environment - * with the namespace table */ - lua_pushvalue(L, LUA_GLOBALSINDEX); + /* export functions (and leave namespace table on top of stack) */ + luaL_module(L, "socket", func, 0); #ifdef LUASOCKET_DEBUG lua_pushstring(L, "DEBUG"); lua_pushboolean(L, 1); @@ -97,8 +97,6 @@ static int base_open(lua_State *L) { lua_pushstring(L, "VERSION"); lua_pushstring(L, LUASOCKET_VERSION); lua_rawset(L, -3); - /* export other functions */ - luaL_openlib(L, NULL, func, 0); return 1; } else { lua_pushstring(L, "unable to initialize library"); @@ -110,7 +108,7 @@ static int base_open(lua_State *L) { /*-------------------------------------------------------------------------*\ * Initializes all library modules. \*-------------------------------------------------------------------------*/ -LUASOCKET_API int luaopen_socket(lua_State *L) { +LUASOCKET_API int luaopen_lsocket(lua_State *L) { int i; base_open(L); for (i = 0; mod[i].name; i++) mod[i].func(L); diff --git a/src/luasocket.h b/src/luasocket.h index 14daef5..33524e3 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -13,7 +13,7 @@ /*-------------------------------------------------------------------------*\ * Current luasocket version \*-------------------------------------------------------------------------*/ -#define LUASOCKET_VERSION "LuaSocket 2.0 (beta2)" +#define LUASOCKET_VERSION "LuaSocket 2.0 (beta3)" /*-------------------------------------------------------------------------*\ * This macro prefixes all exported API functions diff --git a/src/mime.c b/src/mime.c index 5b1d5e8..594135f 100644 --- a/src/mime.c +++ b/src/mime.c @@ -8,6 +8,7 @@ #include #include +#include #include "mime.h" @@ -77,13 +78,9 @@ static UC b64unbase[256]; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -MIME_API int luaopen_mime(lua_State *L) +MIME_API int luaopen_lmime(lua_State *L) { - /* whoever is loading the library replaced the global environment - * with the namespace table */ - lua_pushvalue(L, LUA_GLOBALSINDEX); - /* export functions */ - luaL_openlib(L, NULL, func, 0); + luaL_module(L, "mime", func, 0); /* initialize lookup tables */ qpsetup(qpclass, qpunbase); b64setup(b64unbase); diff --git a/src/mime.lua b/src/mime.lua index fcdc358..3dbcf79 100644 --- a/src/mime.lua +++ b/src/mime.lua @@ -6,9 +6,10 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load other required modules +-- Declare module and import dependencies ----------------------------------------------------------------------------- -local mime = requirelib("mime", "luaopen_mime", getfenv(1)) +module("mime") +local mime = require("lmime") local ltn12 = require("ltn12") -- encode, decode and wrap algorithm tables diff --git a/src/smtp.lua b/src/smtp.lua index c68b750..974d222 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -6,13 +6,19 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load required modules +-- Declare module and import dependencies ----------------------------------------------------------------------------- local socket = require("socket") +local tp = require("socket.tp") + local ltn12 = require("ltn12") local mime = require("mime") -local tp = require("tp") +module("socket.smtp") + +----------------------------------------------------------------------------- +-- Program constants +----------------------------------------------------------------------------- -- timeout for connection TIMEOUT = 60 -- default server used to send e-mails diff --git a/src/socket.lua b/src/socket.lua index be16efe..b3a4269 100644 --- a/src/socket.lua +++ b/src/socket.lua @@ -5,9 +5,10 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load LuaSocket from dynamic library +-- Declare module and import dependencies ----------------------------------------------------------------------------- -local socket = requirelib("luasocket", "luaopen_socket", getfenv(1)) +module("socket") +local socket = require("lsocket") ----------------------------------------------------------------------------- -- Auxiliar functions diff --git a/src/tp.lua b/src/tp.lua index 153541a..ada00d2 100644 --- a/src/tp.lua +++ b/src/tp.lua @@ -6,11 +6,13 @@ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- --- Load required modules +-- Declare module and import dependencies ----------------------------------------------------------------------------- local socket = require("socket") local ltn12 = require("ltn12") +module("socket.tp") + ----------------------------------------------------------------------------- -- Program constants ----------------------------------------------------------------------------- diff --git a/src/url.lua b/src/url.lua index 3fd0aa6..efe7254 100644 --- a/src/url.lua +++ b/src/url.lua @@ -5,6 +5,11 @@ -- RCS ID: $Id$ ----------------------------------------------------------------------------- +----------------------------------------------------------------------------- +-- Declare module +----------------------------------------------------------------------------- +module("socket.url") + ----------------------------------------------------------------------------- -- Encodes a string into its escaped hexadecimal representation -- Input diff --git a/test/httptest.lua b/test/httptest.lua index ce7a93b..71021a4 100644 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -4,15 +4,15 @@ -- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" -- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth local socket = require("socket") +local http = require("socket.http") +local url = require("socket.url") + +local mime = require("mime") +local ltn12 = require("ltn12") -- override protection to make sure we see all errors -- socket.protect = function(s) return s end -local http = require("http") -local mime = require("mime") -local url = require("url") -local ltn12 = require("ltn12") - dofile("testsupport.lua") local host, proxy, request, response, index_file diff --git a/test/mimetest.lua b/test/mimetest.lua index 0b3db33..d9bb772 100644 --- a/test/mimetest.lua +++ b/test/mimetest.lua @@ -8,7 +8,7 @@ local qptest = "qptest.bin" local eqptest = "qptest.bin2" local dqptest = "qptest.bin3" -local b64test = "luasocket.dylib" +local b64test = "lsocket.2.0.dylib" local eb64test = "b64test.bin" local db64test = "b64test.bin2"