Software /
code /
prosody
Changeset
11148:1dc49accb58e
core.moduleapi: Return resource path from module:get_directory() (API BC)
:get_directory has so far returned the base directory of the current
module source code. This has worked well so far to load resources which
tend to be included in the same directory, but with the plugin installer
using LuaRocks, extra resources (e.g. templates and other assets) these
are saved in a completely different directory.
In be73df6765b9 core.modulemanager gained some code for finding that
directory and saving it in module.resource_path but now the question is
how this should be reflected in the API.
A survey of community modules suggest the vast majority use the
:get_directory method for locating templates and other assets, rather
than the code (which would use module:require instead).
Therefore this commit changes :get_directory to return the resource_path
when available. This should work for most modules.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 09 Oct 2020 16:37:15 +0200 |
parents | 11147:82d6c8e627b9 |
children | 11149:28add4b22a74 |
files | core/moduleapi.lua |
diffstat | 1 files changed, 2 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/core/moduleapi.lua Wed Oct 07 22:54:12 2020 +0200 +++ b/core/moduleapi.lua Fri Oct 09 16:37:15 2020 +0200 @@ -496,11 +496,11 @@ 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; + return self.resource_path or self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil; end function api:load_resource(path, mode) - path = resolve_relative_path(self.resource_path or self:get_directory(), path); + path = resolve_relative_path(self:get_directory(), path); return io.open(path, mode); end