Skip to content

format

The format library provides string templating using {expr} placeholders with dot-notation access.

local format = require "format"

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"

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})
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)