Mod & Require: add load function

This commit is contained in:
Van
2026-11-11 21:01:59 +03:00
parent af0b7c8beb
commit 24932b5d2e
2 changed files with 78 additions and 23 deletions

View File

@@ -1,12 +1,14 @@
---Luanti mod
---@class Mod
---@field name string Technical name of the mod.
---@field shortName string
---@field path string Path to the mod folder.
---@field Class any A public class that provides a mod.
---@field require fun(FileName:string):table
Mod = {}
---@class Mod.Info
---@field name string
---@field shortName string
---@field path string
---@field require fun(fileName:string):table
---@field load fun(class:table, fileName:string)
---Returns the mod name without prefixes
---@param name string
---@return string
@@ -18,15 +20,24 @@ end
---Return table with mod name, path and require function.
---@param modname? string Specify a name of mod to get its info
---@return {name: string, shortName: string, path: string, require: fun(FileName : string): table}
---@return Mod.Info
function Mod.getInfo(modname)
local name = modname or core.get_current_modname()
local shortName = getShortModName(name)
local path = core.get_modpath(name)
assert(path ~= nil, ('A mod `%s` does not exist.'):format(name))
local require = Require.getModRequire(name, path)
local require = Require:getModRequire(name, path)
local load = Require:getModLoad(name, path)
return {name = name, shortName = shortName, path = path, require = require}
local info = {
name = name,
shortName = shortName,
path = path,
require = require,
load = load
}
return info
end
--[[
@@ -65,4 +76,4 @@ function Mod:getModClassExtended(ChildClass)
return childClass
end --]]
return Mod
return Mod