Modularity Library
Module loading, initialization, and lifecycle management system for the Lilia framework.
Overview
The modularity library provides comprehensive functionality for managing modules in the Lilia framework. It handles loading, initialization, and management of modules including schemas, preload modules, and regular modules. The library operates on both server and client sides, managing module dependencies, permissions, and lifecycle events. It includes functionality for loading modules from directories, handling module-specific data storage, and ensuring proper initialization order. The library also manages submodules, handles module validation, and provides hooks for module lifecycle events. It ensures that all modules are properly loaded and initialized before gameplay begins.
lia.module.load
đ Purpose
Loads a module from the specified path with the given unique identifier
â° When Called
Called during module initialization, when loading modules from directories, or when manually loading specific modules
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
uniqueID |
string | Unique identifier for the module |
path |
string | File system path to the module directory |
variable |
string, optional | Global variable name to use (defaults to "MODULE") |
skipSubmodules |
boolean, optional | Whether to skip loading submodules |
âŠī¸ Returns
- None
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Load module with custom variable name
lia.module.load("custommodule", "gamemodes/lilia/modules/custom", "CUSTOM_MODULE")
âī¸ High Complexity
-- High: Load module with submodule skipping
lia.module.load("singlemode", "gamemodes/lilia/modules/singlemode", "SINGLE_MODULE", true)
lia.module.initialize
đ Purpose
Initializes the entire module system, loading schemas, preload modules, and regular modules in proper order
â° When Called
Called during gamemode initialization to set up the complete module ecosystem
âŠī¸ Returns
- None
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Initialize with custom schema path
local schemaPath = "gamemodes/mygamemode"
lia.module.load("schema", schemaPath .. "/schema", false, "schema")
lia.module.initialize()
âī¸ High Complexity
-- High: Initialize with custom module loading order
lia.module.initialize()
-- Custom post-initialization logic
for id, mod in pairs(lia.module.list) do
if mod.PostInitialize then
mod:PostInitialize()
end
end
lia.module.loadFromDir
đ Purpose
Loads all modules from a specified directory
â° When Called
Called during module initialization to load multiple modules from a directory, or when manually loading modules from a specific folder
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
directory |
string | Path to the directory containing modules |
group |
string | Type of module group ("module", "schema", etc.) |
skip |
table, optional | Table of module IDs to skip loading |
âŠī¸ Returns
- None
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
-- Simple: Load all modules from a directory
lia.module.loadFromDir("gamemodes/lilia/modules", "module")
đ Medium Complexity
-- Medium: Load modules with specific group type
lia.module.loadFromDir("gamemodes/mygamemode/modules", "module")
âī¸ High Complexity
-- High: Load modules with skip list
local skipModules = {["disabledmodule"] = true, ["testmodule"] = true}
lia.module.loadFromDir("gamemodes/lilia/modules", "module", skipModules)
lia.module.get
đ Purpose
Retrieves a loaded module by its unique identifier
â° When Called
Called when you need to access a specific module's data or functions, or to check if a module is loaded
âī¸ Parameters
| Parameter | Type | Description |
|---|---|---|
identifier |
string | Unique identifier of the module to retrieve |
âŠī¸ Returns
- Module table or nil if not found
đ Realm
Shared
đĄ Example Usage
đ° Low Complexity
đ Medium Complexity
-- Medium: Check if module exists and use it
local module = lia.module.get("inventory")
if module and module.GetItem then
local item = module:GetItem("weapon_pistol")
end
âī¸ High Complexity
-- High: Iterate through all modules and perform operations
for id, module in pairs(lia.module.list) do
local mod = lia.module.get(id)
if mod and mod.OnPlayerSpawn then
mod:OnPlayerSpawn(player)
end
end