mudlet-muddler-luarocks-starter

Package Isolation

Note:
This documentation describes the package isolation system for application code—the main logic and modules of your Mudlet package. It is not applicable for glue code, UI scripting, or quick prototyping in the Mudlet command line or script editor.

Application bootstrapping

This package provides a foundation for developing maintainable, well-isolated Mudlet applications.
The bootstrapping process delivers four key features:

This is pragmatic, best-effort isolation, not security-focused sandboxing.
The goal is to minimize friction and provide a natural level of separation between packages, without extra ceremony.

How the package namespace is named and accessed

When your package is bootstrapped, a unique global table is created for it in Mudlet’s global lua environment. This table serves both as the package’s namespace and as its execution environment. The name is based on your package name, sanitized and wrapped with double underscores, e.g.:

For packageName = "my-package", the namespace is:

    __my_package__

This table acts as the global environment for all your package code and event handlers. You can access it anywhere via:

    _G["__my_package__"]

All the package-level globals, state, and global functions live inside this table, keeping them separate from other packages and Mudlet’s own globals.

Note:
In this system, the terms “environment” and “namespace” refer to the same table: it is both the runtime context for your package code and the container for your package’s public symbols.

Integration and event-based design

This package environment is designed for event-driven integration. The recommended way for other scripts, packages, or users to interact and integrate with your package is by raising events (using Mudlet’s event system) and having your package respond via registered event handlers. This ensures all your code runs within your package’s isolated environment, maintaining separation and avoiding namespace leaks.

If you expose functions or objects in your package’s public namespace (e.g., via _G[“my_package”]), you must take extra care to ensure that your code executes within the package environment:

Package isolation details