Comparison

core/moduleapi.lua @ 9747:c8240f931a68

core.moduleapi: Move util imports to top
author Kim Alvefur <zash@zash.se>
date Sun, 30 Dec 2018 14:26:58 +0100
parent 9733:9ab9aabafa80
child 9748:99199b53019f
comparison
equal deleted inserted replaced
9746:848fd204708c 9747:c8240f931a68
12 local logger = require "util.logger"; 12 local logger = require "util.logger";
13 local pluginloader = require "util.pluginloader"; 13 local pluginloader = require "util.pluginloader";
14 local timer = require "util.timer"; 14 local timer = require "util.timer";
15 local resolve_relative_path = require"util.paths".resolve_relative_path; 15 local resolve_relative_path = require"util.paths".resolve_relative_path;
16 local st = require "util.stanza"; 16 local st = require "util.stanza";
17 local cache = require "util.cache";
18 local promise = require "util.promise";
17 19
18 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; 20 local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat;
19 local error, setmetatable, type = error, setmetatable, type; 21 local error, setmetatable, type = error, setmetatable, type;
20 local ipairs, pairs, select = ipairs, pairs, select; 22 local ipairs, pairs, select = ipairs, pairs, select;
21 local tonumber, tostring = tonumber, tostring; 23 local tonumber, tostring = tonumber, tostring;
362 end 364 end
363 365
364 function api:send_iq(stanza, origin, timeout) 366 function api:send_iq(stanza, origin, timeout)
365 local iq_cache = self._iq_cache; 367 local iq_cache = self._iq_cache;
366 if not iq_cache then 368 if not iq_cache then
367 iq_cache = require "util.cache".new(256, function (_, iq) 369 iq_cache = cache.new(256, function (_, iq)
368 iq.reject("evicted"); 370 iq.reject("evicted");
369 self:unhook(iq.result_event, iq.result_handler); 371 self:unhook(iq.result_event, iq.result_handler);
370 self:unhook(iq.error_event, iq.error_handler); 372 self:unhook(iq.error_event, iq.error_handler);
371 end); 373 end);
372 self._iq_cache = iq_cache; 374 self._iq_cache = iq_cache;
373 end 375 end
374 return require "util.promise".new(function (resolve, reject) 376 return promise.new(function (resolve, reject)
375 local event_type; 377 local event_type;
376 if stanza.attr.from == self.host then 378 if stanza.attr.from == self.host then
377 event_type = "host"; 379 event_type = "host";
378 else -- assume bare since we can't hook full jids 380 else -- assume bare since we can't hook full jids
379 event_type = "bare"; 381 event_type = "bare";