Software /
code /
prosody
Changeset
4790:8bf710b19f65
moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 28 Apr 2012 19:41:04 +0100 |
parents | 4789:bed0c6117358 |
children | 4791:c01066f27a5d |
files | core/moduleapi.lua |
diffstat | 1 files changed, 10 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/core/moduleapi.lua Sat Apr 28 19:38:51 2012 +0100 +++ b/core/moduleapi.lua Sat Apr 28 19:41:04 2012 +0100 @@ -329,4 +329,14 @@ 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;