aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-28 19:41:04 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-28 19:41:04 +0100
commit570492f6278129b438e8f783563ad0473c1ef9bc (patch)
tree47a6b491e0ba8a8115fc77a2382084fc218068bc /core
parent5455ac95160af590c203abf162411c76762117f1 (diff)
downloadprosody-570492f6278129b438e8f783563ad0473c1ef9bc.tar.gz
prosody-570492f6278129b438e8f783563ad0473c1ef9bc.zip
moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory
Diffstat (limited to 'core')
-rw-r--r--core/moduleapi.lua10
1 files changed, 10 insertions, 0 deletions
diff --git a/core/moduleapi.lua b/core/moduleapi.lua
index 703eb268..57367255 100644
--- a/core/moduleapi.lua
+++ b/core/moduleapi.lua
@@ -329,4 +329,14 @@ function api:add_timer(delay, callback)
end);
end
+local path_sep = package.config:sub(1,1);
+function api:get_directory()
+ return self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil;
+end
+
+function api:load_resource(path, mode)
+ path = config.resolve_relative_path(self:get_directory(), path);
+ return io.open(path, mode);
+end
+
return api;