Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit61a33237e0

README.md

shared Module

Cross-tool helpers for the zm toolbox. Every tool inside this toolbox can pull these in with require(".shared").

Purpose

This module holds the small set of helpers that more than one tool in the toolbox needs — protect(fn), which runs a yield-capable world.* mutation under pcall and translates any raised Luau error into a clean message. Tools return their raw values (the tool.assetType wrapper packages them into the system ZmToolResult envelope) and signal failure by raising via error(message); routing the world.* call through protect keeps the raised message clean. Keep it focused: per-tool implementation stays inside each <x>.tool/init.luau (with its own --!desc / --!arg / --!return / --!example annotations).

Usage

local shared = require(".shared")

function M.someTool(...)
    -- Argument-shape failure: raise with a clear message.
    if badArgs then
        error("someTool: reason")
    end
    -- Runtime mutation: route the yield-capable world.* call through
    -- protect so the re-raised message is clean (location prefix
    -- stripped).
    local ok, result = shared.protect(function()
        return world.someMutation(...)
    end)
    if not ok then
        error("someTool: " .. tostring(result))
    end
    return result
end

Exports

See init.luau for the full export surface:

  • shared.protect(fn) — run a yield-capable world.* op under pcall, returning (true, value) on success or (false, cleanMessage) if it raised (the Luau chunk:line: location prefix is stripped). Every mutating tool routes its world.* call through here so the messages it re-raises stay clean.