# HG changeset patch # User Matthew Wild # Date 1223084603 -3600 # Node ID 1cd2a8db392d874aa62fd4225b23eb8ec8bdd7aa # Parent d0505310aec5d82f11c96e1d38e5c83c3eaafa29 New "import" module to help tidy up all the local declarations at the top of modules diff -r d0505310aec5 -r 1cd2a8db392d core/sessionmanager.lua --- a/core/sessionmanager.lua Sat Oct 04 02:42:23 2008 +0100 +++ b/core/sessionmanager.lua Sat Oct 04 02:43:23 2008 +0100 @@ -1,11 +1,9 @@ local tonumber, tostring = tonumber, tostring; -local ipairs = ipairs; +local ipairs, print= ipairs, print; -local m_random = math.random; -local format = string.format; - -local print = print; +local m_random = import("math", "random"); +local format = import("string", "format"); local hosts = hosts; @@ -79,7 +77,7 @@ end send(""); - log("info", "core", "Stream opened successfully"); + log("info", "Stream opened successfully"); session.notopen = nil; end diff -r d0505310aec5 -r 1cd2a8db392d main.lua --- a/main.lua Sat Oct 04 02:42:23 2008 +0100 +++ b/main.lua Sat Oct 04 02:43:23 2008 +0100 @@ -13,6 +13,7 @@ sessions = {}; +require "util.import" require "core.stanza_dispatch" require "core.xmlhandlers" require "core.rostermanager" @@ -24,6 +25,7 @@ require "net.connhandlers" require "util.stanza" require "util.jid" + -- Locals for faster access -- local t_insert = table.insert; diff -r d0505310aec5 -r 1cd2a8db392d util/import.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/util/import.lua Sat Oct 04 02:43:23 2008 +0100 @@ -0,0 +1,13 @@ + +local t_insert = table.insert; +function import(module, ...) + local m = package.loaded[module] or require(module); + if type(m) == "table" and ... then + local ret = {}; + for _, f in ipairs{...} do + t_insert(ret, m[f]); + end + return unpack(ret); + end + return m; +end