Skip to content

Modules

MustBeLeaving edited this page Feb 24, 2026 · 5 revisions

What are modules?

Modules are how you, a user, interacts with MelonLib and its components in a reliable easy way.
They provide 4 key features.

  1. Resolving load-order issues through a well defined load order
  2. Incentivizing an (opinionated) well structured project structure
  3. Meta analysis of code at runtime, although niche it can be quite useful
  4. Separation of client, shared and server files through prefixes.

Creating a module

If you'd like to get started quickly, clone the module template repository

Otherwise, if you'd prefer not to use the template:

  1. Create an addon in garrysmod/addons/
  2. Inside your addon folder create lua/melon/modules/
  3. Inside that folder, create a folder for your module
  4. Inside your module folder, create a folder called src and a file called __init__.lua
  5. Inside __init__.lua paste the following:
return {
    recursive = true,
    extras = {}
}
6. That's it!

Once your module is made, you can use any MelonLib function or interface immediately.

Using MelonLib without a module

If you'd like to use MelonLib without a module, use the hook Melon:DoneLoading:Core to monitor when MelonLib is done loading.

Note

If MelonLib is loaded before your addon is, this hook will have already been called. Condense your file loading into one function and call it with the hook and if melon then!

Clone this wiki locally