aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-09-27 04:01:18 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-09-27 04:01:18 +0000
commita04f15d1ca440006a53bd0d9f98c12e5abebd969 (patch)
tree30d37d74b5c99d5d0e7489a421ec44ad0150113f
parente1d318f26cf53ce9b2c3044d8d138956150488c7 (diff)
downloadluasocket-a04f15d1ca440006a53bd0d9f98c12e5abebd969.tar.gz
luasocket-a04f15d1ca440006a53bd0d9f98c12e5abebd969.tar.bz2
luasocket-a04f15d1ca440006a53bd0d9f98c12e5abebd969.zip
Using new module scheme. Still needs fine tuning.
-rw-r--r--makefile.dist2
-rw-r--r--src/ftp.lua9
-rw-r--r--src/http.lua6
-rw-r--r--src/ltn12.lua5
-rw-r--r--src/luasocket.c10
-rw-r--r--src/luasocket.h2
-rw-r--r--src/mime.c9
-rw-r--r--src/mime.lua5
-rw-r--r--src/smtp.lua10
-rw-r--r--src/socket.lua5
-rw-r--r--src/tp.lua4
-rw-r--r--src/url.lua5
-rw-r--r--test/httptest.lua10
-rw-r--r--test/mimetest.lua2
14 files changed, 52 insertions, 32 deletions
diff --git a/makefile.dist b/makefile.dist
index a0a9313..267709f 100644
--- a/makefile.dist
+++ b/makefile.dist
@@ -2,7 +2,7 @@
2# Distribution makefile 2# Distribution makefile
3#-------------------------------------------------------------------------- 3#--------------------------------------------------------------------------
4 4
5DIST = luasocket-2.0-beta2 5DIST = luasocket-2.0-beta3
6 6
7LUA = \ 7LUA = \
8 ftp.lua \ 8 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 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load required modules 9-- Declare module and import dependencies
10----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
11local socket = require("socket") 11local socket = require("socket")
12local url = require("socket.url")
13local tp = require("socket.tp")
14
12local ltn12 = require("ltn12") 15local ltn12 = require("ltn12")
13local url = require("url") 16
14local tp = require("tp") 17module("socket.ftp")
15 18
16----------------------------------------------------------------------------- 19-----------------------------------------------------------------------------
17-- Program constants 20-- 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 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load required modules 9-- Declare module and import dependencies
10------------------------------------------------------------------------------- 10-------------------------------------------------------------------------------
11local socket = require("socket") 11local socket = require("socket")
12local url = require("socket.url")
12local ltn12 = require("ltn12") 13local ltn12 = require("ltn12")
13local mime = require("mime") 14local mime = require("mime")
14local url = require("url") 15
16module("socket.http")
15 17
16----------------------------------------------------------------------------- 18-----------------------------------------------------------------------------
17-- Program constants 19-- 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 @@
5-- RCS ID: $Id$ 5-- RCS ID: $Id$
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8-----------------------------------------------------------------------------
9-- Declare module
10-----------------------------------------------------------------------------
11module("ltn12")
12
8filter = {} 13filter = {}
9source = {} 14source = {}
10sink = {} 15sink = {}
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 @@
19\*=========================================================================*/ 19\*=========================================================================*/
20#include <lua.h> 20#include <lua.h>
21#include <lauxlib.h> 21#include <lauxlib.h>
22#include <compat-5.1.h>
22 23
23/*=========================================================================*\ 24/*=========================================================================*\
24* LuaSocket includes 25* LuaSocket includes
@@ -85,9 +86,8 @@ static int global_unload(lua_State *L) {
85\*-------------------------------------------------------------------------*/ 86\*-------------------------------------------------------------------------*/
86static int base_open(lua_State *L) { 87static int base_open(lua_State *L) {
87 if (sock_open()) { 88 if (sock_open()) {
88 /* whoever is loading the library replaced the global environment 89 /* export functions (and leave namespace table on top of stack) */
89 * with the namespace table */ 90 luaL_module(L, "socket", func, 0);
90 lua_pushvalue(L, LUA_GLOBALSINDEX);
91#ifdef LUASOCKET_DEBUG 91#ifdef LUASOCKET_DEBUG
92 lua_pushstring(L, "DEBUG"); 92 lua_pushstring(L, "DEBUG");
93 lua_pushboolean(L, 1); 93 lua_pushboolean(L, 1);
@@ -97,8 +97,6 @@ static int base_open(lua_State *L) {
97 lua_pushstring(L, "VERSION"); 97 lua_pushstring(L, "VERSION");
98 lua_pushstring(L, LUASOCKET_VERSION); 98 lua_pushstring(L, LUASOCKET_VERSION);
99 lua_rawset(L, -3); 99 lua_rawset(L, -3);
100 /* export other functions */
101 luaL_openlib(L, NULL, func, 0);
102 return 1; 100 return 1;
103 } else { 101 } else {
104 lua_pushstring(L, "unable to initialize library"); 102 lua_pushstring(L, "unable to initialize library");
@@ -110,7 +108,7 @@ static int base_open(lua_State *L) {
110/*-------------------------------------------------------------------------*\ 108/*-------------------------------------------------------------------------*\
111* Initializes all library modules. 109* Initializes all library modules.
112\*-------------------------------------------------------------------------*/ 110\*-------------------------------------------------------------------------*/
113LUASOCKET_API int luaopen_socket(lua_State *L) { 111LUASOCKET_API int luaopen_lsocket(lua_State *L) {
114 int i; 112 int i;
115 base_open(L); 113 base_open(L);
116 for (i = 0; mod[i].name; i++) mod[i].func(L); 114 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 @@
13/*-------------------------------------------------------------------------*\ 13/*-------------------------------------------------------------------------*\
14* Current luasocket version 14* Current luasocket version
15\*-------------------------------------------------------------------------*/ 15\*-------------------------------------------------------------------------*/
16#define LUASOCKET_VERSION "LuaSocket 2.0 (beta2)" 16#define LUASOCKET_VERSION "LuaSocket 2.0 (beta3)"
17 17
18/*-------------------------------------------------------------------------*\ 18/*-------------------------------------------------------------------------*\
19* This macro prefixes all exported API functions 19* 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 @@
8 8
9#include <lua.h> 9#include <lua.h>
10#include <lauxlib.h> 10#include <lauxlib.h>
11#include <compat-5.1.h>
11 12
12#include "mime.h" 13#include "mime.h"
13 14
@@ -77,13 +78,9 @@ static UC b64unbase[256];
77/*-------------------------------------------------------------------------*\ 78/*-------------------------------------------------------------------------*\
78* Initializes module 79* Initializes module
79\*-------------------------------------------------------------------------*/ 80\*-------------------------------------------------------------------------*/
80MIME_API int luaopen_mime(lua_State *L) 81MIME_API int luaopen_lmime(lua_State *L)
81{ 82{
82 /* whoever is loading the library replaced the global environment 83 luaL_module(L, "mime", func, 0);
83 * with the namespace table */
84 lua_pushvalue(L, LUA_GLOBALSINDEX);
85 /* export functions */
86 luaL_openlib(L, NULL, func, 0);
87 /* initialize lookup tables */ 84 /* initialize lookup tables */
88 qpsetup(qpclass, qpunbase); 85 qpsetup(qpclass, qpunbase);
89 b64setup(b64unbase); 86 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 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load other required modules 9-- Declare module and import dependencies
10----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
11local mime = requirelib("mime", "luaopen_mime", getfenv(1)) 11module("mime")
12local mime = require("lmime")
12local ltn12 = require("ltn12") 13local ltn12 = require("ltn12")
13 14
14-- encode, decode and wrap algorithm tables 15-- 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 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load required modules 9-- Declare module and import dependencies
10----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
11local socket = require("socket") 11local socket = require("socket")
12local tp = require("socket.tp")
13
12local ltn12 = require("ltn12") 14local ltn12 = require("ltn12")
13local mime = require("mime") 15local mime = require("mime")
14local tp = require("tp")
15 16
17module("socket.smtp")
18
19-----------------------------------------------------------------------------
20-- Program constants
21-----------------------------------------------------------------------------
16-- timeout for connection 22-- timeout for connection
17TIMEOUT = 60 23TIMEOUT = 60
18-- default server used to send e-mails 24-- 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 @@
5----------------------------------------------------------------------------- 5-----------------------------------------------------------------------------
6 6
7----------------------------------------------------------------------------- 7-----------------------------------------------------------------------------
8-- Load LuaSocket from dynamic library 8-- Declare module and import dependencies
9----------------------------------------------------------------------------- 9-----------------------------------------------------------------------------
10local socket = requirelib("luasocket", "luaopen_socket", getfenv(1)) 10module("socket")
11local socket = require("lsocket")
11 12
12----------------------------------------------------------------------------- 13-----------------------------------------------------------------------------
13-- Auxiliar functions 14-- 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 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load required modules 9-- Declare module and import dependencies
10----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
11local socket = require("socket") 11local socket = require("socket")
12local ltn12 = require("ltn12") 12local ltn12 = require("ltn12")
13 13
14module("socket.tp")
15
14----------------------------------------------------------------------------- 16-----------------------------------------------------------------------------
15-- Program constants 17-- Program constants
16----------------------------------------------------------------------------- 18-----------------------------------------------------------------------------
diff --git a/src/url.lua b/src/url.lua
index 3fd0aa6..efe7254 100644
--- a/src/url.lua
+++ b/src/url.lua
@@ -6,6 +6,11 @@
6----------------------------------------------------------------------------- 6-----------------------------------------------------------------------------
7 7
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Declare module
10-----------------------------------------------------------------------------
11module("socket.url")
12
13-----------------------------------------------------------------------------
9-- Encodes a string into its escaped hexadecimal representation 14-- Encodes a string into its escaped hexadecimal representation
10-- Input 15-- Input
11-- s: binary string to be encoded 16-- s: binary string to be encoded
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 @@
4-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/" 4-- to "/luasocket-test-cgi" and "/luasocket-test-cgi/"
5-- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth 5-- needs "AllowOverride AuthConfig" on /home/c/diego/tec/luasocket/test/auth
6local socket = require("socket") 6local socket = require("socket")
7local http = require("socket.http")
8local url = require("socket.url")
7 9
8-- override protection to make sure we see all errors
9-- socket.protect = function(s) return s end
10
11local http = require("http")
12local mime = require("mime") 10local mime = require("mime")
13local url = require("url")
14local ltn12 = require("ltn12") 11local ltn12 = require("ltn12")
15 12
13-- override protection to make sure we see all errors
14-- socket.protect = function(s) return s end
15
16dofile("testsupport.lua") 16dofile("testsupport.lua")
17 17
18local host, proxy, request, response, index_file 18local 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"
8local eqptest = "qptest.bin2" 8local eqptest = "qptest.bin2"
9local dqptest = "qptest.bin3" 9local dqptest = "qptest.bin3"
10 10
11local b64test = "luasocket.dylib" 11local b64test = "lsocket.2.0.dylib"
12local eb64test = "b64test.bin" 12local eb64test = "b64test.bin"
13local db64test = "b64test.bin2" 13local db64test = "b64test.bin2"
14 14