Advanced Module Loader - a simple, optimised and good module loader

Advanced Module Loader

Model


:triangular_flag_on_post:Check out my Other posts::triangular_flag_on_post:

CutsceneManager - Manage/Creates cutscene of qualtiy


:question:What is Advanced Module Loader?:question:

Advanced Module Loader, or AML is a module loader which is capable of:

Requiring module in a better way
Calling a startup function
Spawning threads more optimizable
Shutting down the server if any server modules failed to load

:interrobang:Why use a module loader?:interrobang:

A module loader is used for advanced modular frameworks which only uses modules. Of course you don’t have to have a modular framework, but personally it looks more organised than using a lot normal scripts

Example code:

--// EXAMPLE CODE
--// By @rugg3344

local AdvancedModuleLoader = require(script.AdvancedModuleLoader) --// Set this to the location of the module
local modules = script.Parent.Modules --// Set this to the location of your modules container

--// Initializes the main method
AdvancedModuleLoader.process(
	modules,			--// The folder that contains all the modules
	2,					--// How deep you want the search to go
	"initialize"		--// The name of the function that will initialize the modules
)

:scroll:Methods::scroll:

Methods

require:

Requires all the modules in the specified array and returns them

[Params]: modules: { ModuleScript }

[Returns]: { any }

Script:

local requiredModules = AdvancedModuleLoader.require(array)

glob:

Digs into the folder specified and digs as far in as the depth is set.
Note: if depth is set to math.huge, then it will dig as far as it goes

[Params]: modules: Folder, depth: Number

[Returns]: { ModuleScripts }

Script:

local array = AdvancedModuleLoader.glob(
	modules,
	math.huge
)

local requiredModules = AdvancedModuleLoader.require(array)

process:

Uses AdvancedModuleLoader.glob a sup AdvancedModuleLoader.require to load them. Afterwards it will do a startup function with a set name
Note: callFunction is the name of the startup function!

[Params]: modules: Folder, depth: Number, callFunction: string

[Returns]: nil

Script:

AdvancedModuleLoader.process(
	modules,
	2,
	"initialize"
)


:gear:Settings::gear:

Settings

kickWhenError:

Enables/Disables shutdown when the servermodules does not require every module correctly

Value: boolean



If something is wrong or you have any suggestions, the leave them in the comments!

Made by @rugg3344

5 Likes

What is the genuine purpose of this?
Why would you need a module loader to require modules when it can be done with one line of code from any script. If I’m missing something please fill me in, this could be interesting

1 Like

A module loader is used for advanced modular frameworks which only uses modules. Of course you don’t have to have a modular framework, but personally it looks more organised than using a lot normal scripts

I added what i said to the post!