Comparison

util/dependencies.lua @ 6777:5de6b93d0190

util.*: Remove use of module() function, make all module functions local and return them in a table at the end
author Kim Alvefur <zash@zash.se>
date Sat, 21 Feb 2015 10:36:37 +0100
parent 6067:dab7ad6fa23c
child 6778:4009ae66e0f0
comparison
equal deleted inserted replaced
6774:3965662ae091 6777:5de6b93d0190
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 module("dependencies", package.seeall) 9 local function softreq(...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil, lib; end end
10
11 function softreq(...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil, lib; end end
12 10
13 -- Required to be able to find packages installed with luarocks 11 -- Required to be able to find packages installed with luarocks
14 if not softreq "luarocks.loader" then -- LuaRocks 2.x 12 if not softreq "luarocks.loader" then -- LuaRocks 2.x
15 softreq "luarocks.require"; -- LuaRocks <1.x 13 softreq "luarocks.require"; -- LuaRocks <1.x
16 end 14 end
17 15
18 function missingdep(name, sources, msg) 16 local function missingdep(name, sources, msg)
19 print(""); 17 print("");
20 print("**************************"); 18 print("**************************");
21 print("Prosody was unable to find "..tostring(name)); 19 print("Prosody was unable to find "..tostring(name));
22 print("This package can be obtained in the following ways:"); 20 print("This package can be obtained in the following ways:");
23 print(""); 21 print("");
46 else 44 else
47 error("module 'util.ztact' has been deprecated in Prosody 0.8."); 45 error("module 'util.ztact' has been deprecated in Prosody 0.8.");
48 end 46 end
49 end; 47 end;
50 48
51 function check_dependencies() 49 local function check_dependencies()
52 if _VERSION ~= "Lua 5.1" then 50 if _VERSION ~= "Lua 5.1" then
53 print "***********************************" 51 print "***********************************"
54 print("Unsupported Lua version: ".._VERSION); 52 print("Unsupported Lua version: ".._VERSION);
55 print("Only Lua 5.1 is supported."); 53 print("Only Lua 5.1 is supported.");
56 print "***********************************" 54 print "***********************************"
135 fatal = true; 133 fatal = true;
136 end 134 end
137 return not fatal; 135 return not fatal;
138 end 136 end
139 137
140 function log_warnings() 138 local function log_warnings()
139 local ssl = softreq"ssl";
141 if ssl then 140 if ssl then
142 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)"); 141 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
143 if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then 142 if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
144 log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends"); 143 log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends");
145 end 144 end
146 end 145 end
146 local lxp = softreq"lxp";
147 if lxp then 147 if lxp then
148 if not pcall(lxp.new, { StartDoctypeDecl = false }) then 148 if not pcall(lxp.new, { StartDoctypeDecl = false }) then
149 log("error", "The version of LuaExpat on your system leaves Prosody " 149 log("error", "The version of LuaExpat on your system leaves Prosody "
150 .."vulnerable to denial-of-service attacks. You should upgrade to " 150 .."vulnerable to denial-of-service attacks. You should upgrade to "
151 .."LuaExpat 1.3.0 or higher as soon as possible. See " 151 .."LuaExpat 1.3.0 or higher as soon as possible. See "
160 .."http://prosody.im/doc/depends#luaexpat for more information."); 160 .."http://prosody.im/doc/depends#luaexpat for more information.");
161 end 161 end
162 end 162 end
163 end 163 end
164 164
165 return _M; 165 return {
166 softreq = softreq;
167 missingdep = missingdep;
168 check_dependencies = check_dependencies;
169 log_warnings = log_warnings;
170 };