From 1e91290b025fedbdc3b46a929bc569ad15be2b5a Mon Sep 17 00:00:00 2001 From: varttist Date: Fri, 13 Nov 2026 17:06:08 +0300 Subject: [PATCH] `HelperLib`: rename `load()` -> `loadFile()`, add `doFile()` --- mods/SYSTEM/HelperLib/src/Lib.lua | 28 ++++++++++-------- mods/SYSTEM/Mod/init.lua | 9 ++++-- mods/SYSTEM/Require/init.lua | 29 +++++++++++++++---- .../src/PlayerInventoryUI.lua | 12 ++++---- 4 files changed, 52 insertions(+), 26 deletions(-) diff --git a/mods/SYSTEM/HelperLib/src/Lib.lua b/mods/SYSTEM/HelperLib/src/Lib.lua index 0af1bd4..40a4011 100644 --- a/mods/SYSTEM/HelperLib/src/Lib.lua +++ b/mods/SYSTEM/HelperLib/src/Lib.lua @@ -1,20 +1,24 @@ +---SMC helper lib +---@class Smc +Smc = {} + ---@type boolean Smc.isAsync = false local modInfo = Mod.getInfo('smc__system__helper_lib') -local load = modInfo.load +local doFile = modInfo.doFile -- Independent of SMC methods -load(Smc, 'Lib.activeFormspecs') -load(Smc, 'Lib.globalStep') -load(Smc, 'Lib.inventoryHelpers') -load(Smc, 'Lib.color') -load(Smc, 'Lib.itemStackInventory') -load(Smc, 'Lib.nodeSuperClasses') -load(Smc, 'Lib.getObjectByGUID') -load(Smc, 'Lib.receiveFields') -load(Smc, 'Lib.registeredItems') -load(Smc, 'Lib.loads') +doFile('Lib.activeFormspecs') +doFile('Lib.globalStep') +doFile('Lib.inventoryHelpers') +doFile('Lib.color') +doFile('Lib.itemStackInventory') +doFile('Lib.nodeSuperClasses') +doFile('Lib.getObjectByGUID') +doFile('Lib.receiveFields') +doFile('Lib.registeredItems') +doFile('Lib.requires') --- Dependent of SMC methods -load(Smc, 'Lib.matchItemDescription') +doFile('Lib.matchItemDescription') diff --git a/mods/SYSTEM/Mod/init.lua b/mods/SYSTEM/Mod/init.lua index f21fb00..5c7e2bf 100644 --- a/mods/SYSTEM/Mod/init.lua +++ b/mods/SYSTEM/Mod/init.lua @@ -7,7 +7,8 @@ Mod = {} ---@field shortName string ---@field path string ---@field require fun(fileName:string):table ----@field load fun(class:table, fileName:string) +---@field loadFile fun(class:table, fileName:string) +---@field doFile fun(fileName:string) ---Returns the mod name without prefixes ---@param name string @@ -27,14 +28,16 @@ function Mod.getInfo(modname) local path = core.get_modpath(name) assert(path ~= nil, ('A mod `%s` does not exist.'):format(name)) local require = Require:getModRequire(name, path) - local load = Require:getModLoad(name, path) + local loadFile = Require:getModLoadFile(name, path) + local doFile = Require:getModDoFile(path) local info = { name = name, shortName = shortName, path = path, require = require, - load = load + loadFile = loadFile, + doFile = doFile } return info diff --git a/mods/SYSTEM/Require/init.lua b/mods/SYSTEM/Require/init.lua index 725c249..dfc2214 100644 --- a/mods/SYSTEM/Require/init.lua +++ b/mods/SYSTEM/Require/init.lua @@ -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 diff --git a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua index 2d62c33..32a8563 100644 --- a/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua +++ b/mods/UI/PlayerInventoryUI/src/PlayerInventoryUI.lua @@ -13,7 +13,7 @@ local BaseUI, Formspec = Smc.requireBaseUI(), Smc.requireFormspec() local modInfo = Mod.getInfo('smc__ui__player_inventory') local require = modInfo.require -local load = modInfo.load +local loadFile = modInfo.loadFile ---The distance at which a player can interact with blocks that have a node-tab. --- @@ -434,10 +434,10 @@ end) --- Inventory action handling --- -load(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.general') -load(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.itemsList') -load(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.crafts') -load(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.adminList') -load(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.equip') +loadFile(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.general') +loadFile(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.itemsList') +loadFile(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.crafts') +loadFile(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.adminList') +loadFile(PlayerInventoryUI, 'PlayerInventoryUI.actionHandling.equip') return PlayerInventoryUI