Software / code / prosody
Comparison
util/pluginloader.lua @ 4149:3c1b153c2856
util.pluginloader: Return full file path from internal file loader on success, not just the name.
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sun, 20 Feb 2011 20:01:05 +0500 |
| parent | 4121:ea7e3f22f898 |
| child | 4150:2894ca33ec45 |
comparison
equal
deleted
inserted
replaced
| 4148:65f22ed19b9e | 4149:3c1b153c2856 |
|---|---|
| 18 local loadstring, pairs = loadstring, pairs; | 18 local loadstring, pairs = loadstring, pairs; |
| 19 | 19 |
| 20 module "pluginloader" | 20 module "pluginloader" |
| 21 | 21 |
| 22 local function load_file(name) | 22 local function load_file(name) |
| 23 local file, err; | 23 local file, err, path; |
| 24 for i=1,#plugin_dir do | 24 for i=1,#plugin_dir do |
| 25 file, err = io_open(plugin_dir[i]..name); | 25 path = plugin_dir[i]..name; |
| 26 file, err = io_open(path); | |
| 26 if file then break; end | 27 if file then break; end |
| 27 end | 28 end |
| 28 if not file then return file, err; end | 29 if not file then return file, err; end |
| 29 local content = file:read("*a"); | 30 local content = file:read("*a"); |
| 30 file:close(); | 31 file:close(); |
| 31 return content, name; | 32 return content, path; |
| 32 end | 33 end |
| 33 | 34 |
| 34 function load_resource(plugin, resource, loader) | 35 function load_resource(plugin, resource, loader) |
| 35 local path, name = plugin:match("([^/]*)/?(.*)"); | 36 local path, name = plugin:match("([^/]*)/?(.*)"); |
| 36 if name == "" then | 37 if name == "" then |