pInterp interpolates strings with position-independent arguments.

Dependencies: None.

local pInterp = require("p_interp")

print(pInterp("The $1 brown fox $3 over the lazy $2.", "quick", "dog", "jumps"))

-->The quick brown fox jumps over the lazy dog.
Table of Contents

API

pInterp

Interpolates up to nine arguments in a string.

local interpolated = pInterp(s, ...)
  • s: The string to inject values into. The insertion points for arguments are $1 for the first, $2 for the second, and so on, up to $9.

  • …​: A vararg list. All values are converted to strings.

Returns: The interpolated string.

Notes

The character $ can be escaped in s by writing $$.

If you need to interpolate more than $1 - $9, consider breaking the message into smaller strings, or use string.gsub directly with a replacement table.


VERSION: 2.106