Skip to content

API Modules

Piggo41 edited this page Oct 12, 2026 · 8 revisions

Modules

Lua API / Modules

betamoon.modules:export(name, values)

Stages a table for publication after the exporting script initializes successfully.

Parameter Type Requirement
name string Required, non-empty, unique across exporting scripts.
values table Required; the actual table to share.

Export during script loading/initialization. A different owner cannot export the same name. Exporting two different tables under the same name during one pending initialization is an error. Failed initialization discards pending exports; unloading removes owned exports.

local public = { multiplier = 2 }
betamoon.modules:export("shared_settings", public)

Construct the table inside modInit() and export it after preparing its contents.

betamoon.modules:import(name)

Returns the published table with the supplied module name.

Parameter Type Requirement
name string Required, non-empty exported module name.

Errors: no published module with that name. The result is the shared table, not a detached copy.

-- Top level: dependencies = { "Settings Script" }
-- Inside modInit:
local settings = betamoon.modules:import("shared_settings")
local multiplier = settings.multiplier

The dependency names the exporter script's name, not its module name or filename. Do not rely on ordinary require to establish BetaMoon dependency order.

Packaged mods may use ordinary require("path.to.module") for private files inside the same package. Those modules are isolated and cached per mod generation. They are not published to other mods. Use betamoon.modules:export and betamoon.modules:import for cross-mod sharing. See Packaged Lua mods.

Examples: Export, import.

Clone this wiki locally