HelperLib: rename load() -> loadFile(), add doFile()

This commit is contained in:
Van
2026-11-13 17:06:08 +03:00
parent 2243ed7532
commit 1e91290b02
4 changed files with 52 additions and 26 deletions

View File

@@ -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