Fine tuning the "require" business.
This commit is contained in:
parent
c23240726e
commit
5ca1049ab4
17 changed files with 133 additions and 116 deletions
11
src/ftp.lua
11
src/ftp.lua
|
@ -13,6 +13,7 @@ local socket = _G[LUASOCKET_LIBNAME]
|
|||
-- require other modules
|
||||
require("ltn12")
|
||||
require("url")
|
||||
require("tp")
|
||||
|
||||
-- create namespace inside LuaSocket namespace
|
||||
socket.ftp = socket.ftp or {}
|
||||
|
@ -101,7 +102,9 @@ function metat.__index:send(sendt)
|
|||
local data
|
||||
socket.try(self.pasvt or self.portt, "need port or pasv first")
|
||||
if self.pasvt then data = socket.try(pasv(self.pasvt)) end
|
||||
socket.try(self.tp:command(sendt.command or "stor", sendt.argument))
|
||||
local argument = sendt.argument or string.gsub(sendt.path, "^/", "")
|
||||
local command = sendt.command or "stor"
|
||||
socket.try(self.tp:command(command, argument))
|
||||
local code, reply = socket.try(self.tp:check{"2..", "1.."})
|
||||
if self.portt then data = socket.try(port(self.portt)) end
|
||||
local step = sendt.step or ltn12.pump.step
|
||||
|
@ -128,7 +131,9 @@ function metat.__index:receive(recvt)
|
|||
local data
|
||||
socket.try(self.pasvt or self.portt, "need port or pasv first")
|
||||
if self.pasvt then data = socket.try(pasv(self.pasvt)) end
|
||||
socket.try(self.tp:command(recvt.command or "retr", recvt.argument))
|
||||
local argument = recvt.argument or string.gsub(recvt.path, "^/", "")
|
||||
local command = recvt.command or "retr"
|
||||
socket.try(self.tp:command(command, argument))
|
||||
local code = socket.try(self.tp:check{"1..", "2.."})
|
||||
if self.portt then data = socket.try(port(self.portt)) end
|
||||
local source = socket.source("until-closed", data)
|
||||
|
@ -200,8 +205,6 @@ local function parse(url)
|
|||
putt.type = socket.skip(2, string.find(putt.params, pat))
|
||||
socket.try(putt.type == "a" or putt.type == "i")
|
||||
end
|
||||
-- skip first backslash in path
|
||||
putt.argument = string.sub(putt.path, 2)
|
||||
return putt
|
||||
end
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ local socket = _G[LUASOCKET_LIBNAME]
|
|||
-- require other modules
|
||||
require("ltn12")
|
||||
require("mime")
|
||||
-- get MIME namespace
|
||||
local mime = _G[MIME_LIBNAME]
|
||||
require("url")
|
||||
|
||||
-- create namespace inside LuaSocket namespace
|
||||
|
|
|
@ -25,11 +25,10 @@
|
|||
\*=========================================================================*/
|
||||
#include "luasocket.h"
|
||||
|
||||
#include "base.h"
|
||||
#include "auxiliar.h"
|
||||
#include "base.h"
|
||||
#include "timeout.h"
|
||||
#include "buffer.h"
|
||||
#include "socket.h"
|
||||
#include "inet.h"
|
||||
#include "tcp.h"
|
||||
#include "udp.h"
|
||||
|
@ -40,10 +39,10 @@
|
|||
* Modules
|
||||
\*-------------------------------------------------------------------------*/
|
||||
static const luaL_reg mod[] = {
|
||||
{"auxiliar", aux_open},
|
||||
{"base", base_open},
|
||||
{"aux", aux_open},
|
||||
{"tm", tm_open},
|
||||
{"buf", buf_open},
|
||||
{"timeout", tm_open},
|
||||
{"buffer", buf_open},
|
||||
{"inet", inet_open},
|
||||
{"tcp", tcp_open},
|
||||
{"udp", udp_open},
|
||||
|
@ -55,14 +54,8 @@ static const luaL_reg mod[] = {
|
|||
/*-------------------------------------------------------------------------*\
|
||||
* Initializes all library modules.
|
||||
\*-------------------------------------------------------------------------*/
|
||||
LUASOCKET_API int luaopen_socket(lua_State *L)
|
||||
{
|
||||
LUASOCKET_API int luaopen_socket(lua_State *L) {
|
||||
int i;
|
||||
if (!sock_open()) {
|
||||
lua_pushnil(L);
|
||||
lua_pushstring(L, "unable to initialize library");
|
||||
return 2;
|
||||
}
|
||||
for (i = 0; mod[i].name; i++)
|
||||
mod[i].func(L);
|
||||
return 1;
|
||||
|
|
|
@ -82,8 +82,7 @@ int luaopen_mime(lua_State *L)
|
|||
/* initialize lookup tables */
|
||||
qpsetup(qpclass, qpunbase);
|
||||
b64setup(b64unbase);
|
||||
lua_pop(L, 1);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================================================*\
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
* To make the code as simple as possible, the select function is
|
||||
* implemented int Lua, with a few helper functions written in C.
|
||||
*
|
||||
* Each object that can be passed to the select function has to be in the
|
||||
* group select{able} and export two methods: fd() and dirty(). Fd returns
|
||||
* the descriptor to be passed to the select function. Dirty() should return
|
||||
* true if there is data ready for reading (required for buffered input).
|
||||
* Each object that can be passed to the select function has to export two
|
||||
* methods: fd() and dirty(). Fd returns the descriptor to be passed to the
|
||||
* select function. Dirty() should return true if there is data ready for
|
||||
* reading (required for buffered input).
|
||||
*
|
||||
* RCS ID: $Id$
|
||||
\*=========================================================================*/
|
||||
|
|
|
@ -6,11 +6,12 @@
|
|||
-- RCS ID: $Id$
|
||||
-----------------------------------------------------------------------------
|
||||
-- make sure LuaSocket is loaded
|
||||
require"socket"
|
||||
require("socket")
|
||||
-- get LuaSocket namespace
|
||||
local socket = _G[LUASOCKET_LIBNAME]
|
||||
|
||||
require"ltn12"
|
||||
require("ltn12")
|
||||
require("tp")
|
||||
|
||||
-- create smtp namespace inside LuaSocket namespace
|
||||
local smtp = socket.smtp or {}
|
||||
|
|
|
@ -38,6 +38,7 @@ typedef struct sockaddr SA;
|
|||
* interface to sockets
|
||||
\*=========================================================================*/
|
||||
int sock_open(void);
|
||||
int sock_close(void);
|
||||
void sock_destroy(p_sock ps);
|
||||
void sock_shutdown(p_sock ps, int how);
|
||||
int sock_send(p_sock ps, const char *data, size_t count,
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
-- RCS ID: $Id$
|
||||
-----------------------------------------------------------------------------
|
||||
-- make sure LuaSocket is loaded
|
||||
if not LUASOCKET_LIBNAME then error('module requires LuaSocket') end
|
||||
require("socket")
|
||||
-- get LuaSocket namespace
|
||||
local socket = _G[LUASOCKET_LIBNAME]
|
||||
if not socket then error('module requires LuaSocket') end
|
||||
|
||||
-- create namespace inside LuaSocket namespace
|
||||
socket.tp = socket.tp or {}
|
||||
-- make all module globals fall into namespace
|
||||
|
@ -35,6 +35,7 @@ local function get_reply(control)
|
|||
-- reply ends with same code
|
||||
until code == current and sep == " "
|
||||
end
|
||||
print(reply)
|
||||
return code, reply
|
||||
end
|
||||
|
||||
|
@ -58,6 +59,7 @@ function metat.__index:check(ok)
|
|||
end
|
||||
|
||||
function metat.__index:command(cmd, arg)
|
||||
print(cmd, arg)
|
||||
if arg then return self.control:send(cmd .. " " .. arg.. "\r\n")
|
||||
else return self.control:send(cmd .. "\r\n") end
|
||||
end
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
require("socket")
|
||||
-- get LuaSocket namespace
|
||||
local socket = _G[LUASOCKET_LIBNAME]
|
||||
|
||||
-- create url namespace inside LuaSocket namespace
|
||||
local url = socket.url or {}
|
||||
socket.url = url
|
||||
-- make all module globals fall into smtp namespace
|
||||
-- make all module globals fall into url namespace
|
||||
setmetatable(url, { __index = _G })
|
||||
setfenv(1, url)
|
||||
|
||||
|
|
|
@ -42,6 +42,14 @@ int sock_open(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Close module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
int sock_close(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Close and inutilize socket
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
|
|
@ -37,6 +37,15 @@ int sock_open(void)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Close module
|
||||
\*-------------------------------------------------------------------------*/
|
||||
int sock_close(void)
|
||||
{
|
||||
WSACleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Select with int timeout in ms
|
||||
\*-------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue