In C, I can tell printf print the arguments in a different order than the order in which they are passed:
printf("%2$d %1$d\n", 10, 20);
However, if I try to do the same in Lua, I get an error:
print(string.format("%2$d %1$d\n", 10, 20))
invalid option '%$' to 'format'
Is there a way to create a Lua format string that causes string.format to write the second argument before the first? I work with internationalization, and changing the format string is easy, but changing the order of the arguments is much more complicated.
I would expect the method I used in C to work with Lua, because according to the manual , string.format should get the same parameters as sprintf . The %2$ directives are not part of ANSI C, or are they Lua guidelines, just forgetting to mention that they are not supported?
lua printf
hugomg
source share