From 31dd27582930bbd9e297531046b223c35491baa5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 28 Apr 2012 19:41:04 +0100 Subject: moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory --- core/moduleapi.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core') 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; -- cgit v1.2.3