HelperLib: rename load() -> loadFile(), add doFile()
This commit is contained in:
@@ -52,17 +52,16 @@ end
|
||||
---@param modName string Namespace identifier for the module (prevents global collisions)
|
||||
---@param modPath string Absolute base path to the module's directory
|
||||
---@return function load Custom load function scoped to the specified module
|
||||
function Require:getModLoad(modName, modPath)
|
||||
function Require:getModLoadFile(modName, modPath)
|
||||
---Custom load function for loading modules.
|
||||
---
|
||||
---Resolves file paths relative to modPath/src and converts dot notation into path separators.
|
||||
---@param class table A class within the scope of which a script is to be executed
|
||||
---@param fileName string Module path in dot-notation (e.g. "lib.utils")
|
||||
local function load(class, fileName)
|
||||
local function loadFile(class, fileName)
|
||||
local fullName = modName..'..'..fileName
|
||||
|
||||
local module = loadedModules[fullName]
|
||||
if module ~= nil then
|
||||
if loadedModules[fullName] ~= nil then
|
||||
error(('Repeated execute of script `%s` is not allowed.'):format(modPath))
|
||||
end
|
||||
|
||||
@@ -76,7 +75,27 @@ function Require:getModLoad(modName, modPath)
|
||||
loadedModules[fullName] = true
|
||||
end
|
||||
|
||||
return load
|
||||
return loadFile
|
||||
end
|
||||
|
||||
---Creates dofile function for loading files.
|
||||
---
|
||||
---This loading function will execute a standard `dofile` for the specified script.
|
||||
---@param modPath string Absolute base path to the module's directory
|
||||
---@return function doFile Custom dofile function scoped to the specified file
|
||||
function Require:getModDoFile(modPath)
|
||||
---Custom `dofile` function for loading files.
|
||||
---
|
||||
---Resolves file paths relative to modPath/src and converts dot notation into path separators.
|
||||
---@param fileName string File path in dot-notation (e.g. "lib.utils")
|
||||
---@return any?
|
||||
local function doFile(fileName)
|
||||
local result = dofile(self:getFilePath(modPath, fileName))
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return doFile
|
||||
end
|
||||
|
||||
return Require
|
||||
|
||||
Reference in New Issue
Block a user