Software / code / prosody
Comparison
core/moduleapi.lua @ 4790:8bf710b19f65
moduleapi: Add module:get_directory() to get module file's directory, and module:load_resource() to load a file relative to that directory
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sat, 28 Apr 2012 19:41:04 +0100 |
| parent | 4750:b3525f3c2fee |
| child | 4854:dab55c6f7710 |
comparison
equal
deleted
inserted
replaced
| 4789:bed0c6117358 | 4790:8bf710b19f65 |
|---|---|
| 327 if self.loaded == false then return; end | 327 if self.loaded == false then return; end |
| 328 return callback(t); | 328 return callback(t); |
| 329 end); | 329 end); |
| 330 end | 330 end |
| 331 | 331 |
| 332 local path_sep = package.config:sub(1,1); | |
| 333 function api:get_directory() | |
| 334 return self.path and (self.path:gsub("%"..path_sep.."[^"..path_sep.."]*$", "")) or nil; | |
| 335 end | |
| 336 | |
| 337 function api:load_resource(path, mode) | |
| 338 path = config.resolve_relative_path(self:get_directory(), path); | |
| 339 return io.open(path, mode); | |
| 340 end | |
| 341 | |
| 332 return api; | 342 return api; |