Changeset

6780:647adfd8f738

net.*: Remove use of module() function
author Kim Alvefur <zash@zash.se>
date Sat, 21 Feb 2015 10:45:24 +0100
parents 6779:6236668da30a
children 6781:05cd80ec107c
files net/adns.lua net/connlisteners.lua net/dns.lua net/http.lua net/httpserver.lua
diffstat 5 files changed, 44 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/net/adns.lua	Sat Feb 21 10:42:19 2015 +0100
+++ b/net/adns.lua	Sat Feb 21 10:45:24 2015 +0100
@@ -16,9 +16,9 @@
 
 local function dummy_send(sock, data, i, j) return (j-i)+1; end
 
-module "adns"
+local _ENV = nil;
 
-function lookup(handler, qname, qtype, qclass)
+local function lookup(handler, qname, qtype, qclass)
 	return coroutine.wrap(function (peek)
 				if peek then
 					log("debug", "Records for %s already cached, using those...", qname);
@@ -43,12 +43,12 @@
 			end)(dns.peek(qname, qtype, qclass));
 end
 
-function cancel(handle, call_handler, reason)
+local function cancel(handle, call_handler, reason)
 	log("warn", "Cancelling DNS lookup for %s", tostring(handle[3]));
 	dns.cancel(handle[1], handle[2], handle[3], handle[4], call_handler);
 end
 
-function new_async_socket(sock, resolver)
+local function new_async_socket(sock, resolver)
 	local peername = "<unknown>";
 	local listener = {};
 	local handler = {};
@@ -88,4 +88,8 @@
 
 dns.socket_wrapper_set(new_async_socket);
 
-return _M;
+return {
+	lookup = lookup;
+	cancel = cancel;
+	new_async_socket = new_async_socket;
+};
--- a/net/connlisteners.lua	Sat Feb 21 10:42:19 2015 +0100
+++ b/net/connlisteners.lua	Sat Feb 21 10:45:24 2015 +0100
@@ -2,14 +2,17 @@
 local log = require "util.logger".init("net.connlisteners");
 local traceback = debug.traceback;
 
-module "httpserver"
+local _ENV = nil;
 
-function fail()
+local function fail()
 	log("error", "Attempt to use legacy connlisteners API. For more info see http://prosody.im/doc/developers/network");
 	log("error", "Legacy connlisteners API usage, %s", traceback("", 2));
 end
 
-register, deregister = fail, fail;
-get, start = fail, fail, epic_fail;
-
-return _M;
+return {
+	register = fail;
+	register = fail;
+	get = fail;
+	start = fail;
+	-- epic fail
+};
--- a/net/dns.lua	Sat Feb 21 10:42:19 2015 +0100
+++ b/net/dns.lua	Sat Feb 21 10:45:24 2015 +0100
@@ -71,8 +71,8 @@
 local default_timeout = 15;
 
 -------------------------------------------------- module dns
-module('dns')
-local dns = _M;
+local _ENV = nil;
+local dns = {};
 
 
 -- dns type & class codes ------------------------------ dns type & class codes
--- a/net/http.lua	Sat Feb 21 10:42:19 2015 +0100
+++ b/net/http.lua	Sat Feb 21 10:45:24 2015 +0100
@@ -24,7 +24,7 @@
 
 local log = require "util.logger".init("http");
 
-module "http"
+local _ENV = nil;
 
 local requests = {}; -- Open requests
 
@@ -76,6 +76,13 @@
 	requests[conn] = nil;
 end
 
+local function destroy_request(request)
+	if request.conn then
+		request.conn = nil;
+		request.handler:close()
+	end
+end
+
 local function request_reader(request, data, err)
 	if not request.parser then
 		local function error_cb(reason)
@@ -107,7 +114,7 @@
 end
 
 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
-function request(u, ex, callback)
+local function request(u, ex, callback)
 	local req = url.parse(u);
 
 	if not (req and req.host) then
@@ -189,17 +196,12 @@
 	return req;
 end
 
-function destroy_request(request)
-	if request.conn then
-		request.conn = nil;
-		request.handler:close()
-	end
-end
-
-local urlencode, urldecode = util_http.urlencode, util_http.urldecode;
-local formencode, formdecode = util_http.formencode, util_http.formdecode;
-
-_M.urlencode, _M.urldecode = urlencode, urldecode;
-_M.formencode, _M.formdecode = formencode, formdecode;
-
-return _M;
+return {
+	request = request;
+	
+	-- COMPAT
+	urlencode = util_http.urlencode;
+	urldecode = util_http.urldecode;
+	formencode = util_http.formencode;
+	formdecode = util_http.formdecode;
+};
--- a/net/httpserver.lua	Sat Feb 21 10:42:19 2015 +0100
+++ b/net/httpserver.lua	Sat Feb 21 10:45:24 2015 +0100
@@ -2,14 +2,15 @@
 local log = require "util.logger".init("net.httpserver");
 local traceback = debug.traceback;
 
-module "httpserver"
+local _ENV = nil;
 
 function fail()
 	log("error", "Attempt to use legacy HTTP API. For more info see http://prosody.im/doc/developers/legacy_http");
 	log("error", "Legacy HTTP API usage, %s", traceback("", 2));
 end
 
-new, new_from_config = fail, fail;
-set_default_handler = fail;
-
-return _M;
+return {
+	new = fail;
+	new_from_config = fail;
+	set_default_handler = fail;
+};