Created
April 28, 2024 12:23
-
-
Save Mark-Marks/dfa3542de15f8d9605493fa01d4ef81c to your computer and use it in GitHub Desktop.
A tiny module loader with lifecycles for Roblox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type Singleton = { | |
| start: (() -> ())?, | |
| [string]: any, | |
| } | |
| local Framework = {} | |
| Framework.modules = {} :: { ModuleScript } | |
| Framework.started = false | |
| function Framework.add_module(module: ModuleScript) | |
| table.insert(Framework.modules, module) | |
| end | |
| function Framework.add_modules(parent: Folder) | |
| for _, child in parent:GetChildren() do | |
| if not child:IsA("ModuleScript") then | |
| continue | |
| end | |
| table.insert(Framework.modules, child) | |
| end | |
| end | |
| function Framework.start() | |
| local start = os.clock() | |
| for _, module in Framework.modules do | |
| local singleton = require(module) :: Singleton | |
| if not singleton.start then | |
| continue | |
| end | |
| singleton.start() | |
| end | |
| local took = os.clock() - start | |
| print(`✅ Took {took}s to load {#Framework.modules} modules`) | |
| end | |
| return Framework |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment