Software /
code /
prosody
Diff
core/moduleapi.lua @ 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 |
parent | 4750:b3525f3c2fee |
child | 4854:dab55c6f7710 |
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;