format
The format library provides string templating using {expr} placeholders with dot-notation access.
Loading
Section titled “Loading”local format = require "format"format(pattern)
Section titled “format(pattern)”Returns a function that accepts an arguments table and returns a formatted string.
local fmt = format("{p.name} has {count} apples")local result = fmt({p = {name = "Alex"}, count = 3})-- "Alex has 3 apples"broadcastFormat(pattern)
Section titled “broadcastFormat(pattern)”Returns a function that formats the string and broadcasts it to all players in one call.
local bf = broadcastFormat("*{p.name} throws a fireball at {t.name}*")bf({p = ctx.player, t = target})Examples
Section titled “Examples”local format = require "format"
register("shout <message:text>", function(ctx, message) local fmt = format("*{p.name} shouts: {msg}*") local text = fmt({p = ctx.player, msg = message}) ctx.player:sendMessage(text)end)With broadcast:
local bf = broadcastFormat("*{p.name} throws a fireball at {t.name}*")
register("throw <target:player>", function(ctx) local target = ctx.args.target bf({p = ctx.player, t = target})end)