Software /
code /
prosody
Comparison
core/moduleapi.lua @ 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 |
parent | 11146:87d6f5924ae9 |
child | 11523:5f15ab7c6ae5 |
comparison
equal
deleted
inserted
replaced
11147:82d6c8e627b9 | 11148:1dc49accb58e |
---|---|
494 return setmetatable(t, timer_mt); | 494 return setmetatable(t, timer_mt); |
495 end | 495 end |
496 | 496 |
497 local path_sep = package.config:sub(1,1); | 497 local path_sep = package.config:sub(1,1); |
498 function api:get_directory() | 498 function api:get_directory() |
499 return self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil; | 499 return self.resource_path or self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil; |
500 end | 500 end |
501 | 501 |
502 function api:load_resource(path, mode) | 502 function api:load_resource(path, mode) |
503 path = resolve_relative_path(self.resource_path or self:get_directory(), path); | 503 path = resolve_relative_path(self:get_directory(), path); |
504 return io.open(path, mode); | 504 return io.open(path, mode); |
505 end | 505 end |
506 | 506 |
507 function api:open_store(name, store_type) | 507 function api:open_store(name, store_type) |
508 return require"core.storagemanager".open(self.host, name or self.name, store_type); | 508 return require"core.storagemanager".open(self.host, name or self.name, store_type); |