Skip to content

daurnimator/f-strings

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

f-strings

String interpolation for Lua, inspired by f-strings, a form of string interpolation coming in Python 3.6.

This module started as a blog post showcasing that Lua already has all features necessary to implement the equivalent Python feature.

Usage

Require the F module and then use it directly on strings. Any {expression} occurring in them will be evaluated and interpolated directly in the string.

local F = require("F")

local f = 99
local c = (f - 32) / 9 * 5
print(F"{f} degrees Fahrenheit is {c:%.2f} degrees Celsius")

Almost any Lua expression can be inserted (apart from two minor parsing caveats: ":%" is used as a separator for specifying formatting (according to the same rules of string.format), and curly braces within expressions must be well-nested).

See the examples directory for more examples.

Author

Hisham Muhammad - http://twitter.com/hisham_hm - http://hisham.hm/

License

MIT/X11, the same as Lua.

About

String interpolation for Lua

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • Lua 100.0%