Returns a formatted string containing specified values. Alias for the standard library function string.format. This version, however, includes the positional argument specifiers from Lua 4.0.

Lua does not support the ANSI C format specifiers *, l, L, n, p, and h but includes an extra specifier, q, which formats a string in a form suitable to be safely read back by the Lua interpreter: the string is written between double quotes, and all double quotes, newlines, embedded zeros, and backslashes in the string are correctly escaped when written.

See also Lua library functions.


formatted = format("formatString", ...)


  • formatString - A string containing format specifiers as per the ANSI C printf function (string)
  • ... - A list of values to be included in the formatted string (list)


  • formatted - The formatted string (number)


string.format("%s %q", "Hello", "Azeroth!")   -- string and quoted string
-- returns 'Hello "Azeroth!"'
string.format("%c%c%c", 76,117,97)             -- char
-- returns 'Lua'
string.format("%e, %E", math.pi,math.pi)       -- exponent
-- returns '3.141593e+000, 3.141593E+000'
string.format("%f, %g", math.pi,math.pi)       -- float and compact float
--returns '3.141593, 3.14159'
string.format("%d, %i, %u", -100,-100,-100)    -- signed, signed, unsigned integer
-- returns '-100, -100, 4294967196'
string.format("%o, %x, %X", -100,-100,-100)    -- octal, hex, hex
-- returns '37777777634, ffffff9c, FFFFFF9C'
This function is defined in the Lua standard libraries