# HG changeset patch # User Matthew Wild # Date 1335638464 -3600 # Node ID 8bf710b19f65231b2a1924e5555e43c4084ca32b # Parent bed0c6117358d47b368094bd21629ce2fe166fed moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory diff -r bed0c6117358 -r 8bf710b19f65 core/moduleapi.lua --- 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;