Software / code / prosody
Comparison
util/pluginloader.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 | 6031:8796aa94c4b5 |
| child | 7115:805d068d2fd5 |
comparison
equal
deleted
inserted
replaced
| 6774:3965662ae091 | 6777:5de6b93d0190 |
|---|---|
| 15 end | 15 end |
| 16 | 16 |
| 17 local io_open = io.open; | 17 local io_open = io.open; |
| 18 local envload = require "util.envload".envload; | 18 local envload = require "util.envload".envload; |
| 19 | 19 |
| 20 module "pluginloader" | 20 local function load_file(names) |
| 21 | |
| 22 function load_file(names) | |
| 23 local file, err, path; | 21 local file, err, path; |
| 24 for i=1,#plugin_dir do | 22 for i=1,#plugin_dir do |
| 25 for j=1,#names do | 23 for j=1,#names do |
| 26 path = plugin_dir[i]..names[j]; | 24 path = plugin_dir[i]..names[j]; |
| 27 file, err = io_open(path); | 25 file, err = io_open(path); |
| 33 end | 31 end |
| 34 end | 32 end |
| 35 return file, err; | 33 return file, err; |
| 36 end | 34 end |
| 37 | 35 |
| 38 function load_resource(plugin, resource) | 36 local function load_resource(plugin, resource) |
| 39 resource = resource or "mod_"..plugin..".lua"; | 37 resource = resource or "mod_"..plugin..".lua"; |
| 40 | 38 |
| 41 local names = { | 39 local names = { |
| 42 "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua | 40 "mod_"..plugin..dir_sep..plugin..dir_sep..resource; -- mod_hello/hello/mod_hello.lua |
| 43 "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua | 41 "mod_"..plugin..dir_sep..resource; -- mod_hello/mod_hello.lua |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 return load_file(names); | 46 return load_file(names); |
| 49 end | 47 end |
| 50 | 48 |
| 51 function load_code(plugin, resource, env) | 49 local function load_code(plugin, resource, env) |
| 52 local content, err = load_resource(plugin, resource); | 50 local content, err = load_resource(plugin, resource); |
| 53 if not content then return content, err; end | 51 if not content then return content, err; end |
| 54 local path = err; | 52 local path = err; |
| 55 local f, err = envload(content, "@"..path, env); | 53 local f, err = envload(content, "@"..path, env); |
| 56 if not f then return f, err; end | 54 if not f then return f, err; end |
| 57 return f, path; | 55 return f, path; |
| 58 end | 56 end |
| 59 | 57 |
| 60 return _M; | 58 return { |
| 59 load_file = load_file; | |
| 60 load_resource = load_resource; | |
| 61 load_code = load_code; | |
| 62 }; |