moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory
--- 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;