If you want a version of string.format that allows you to specify which argument to use for each token, you can take a look at lua-wow's string library code[1]. The str_format function is almost identical to Lua 5.1's str_format, the main difference is on lines 771 to 778 (for the actual formatting) and 819-820 (for error reporting). It also adds escaping for carriage return characters in the %q token. [1] https://github.com/cogwheel/lua-wow/blob/master/src/lstrlib.c#L684