Skip to content

Instantly share code, notes, and snippets.

@Fingercomp
Last active March 21, 2020 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fingercomp/13c0add5e0bbeeac7fa90730172f7277 to your computer and use it in GitHub Desktop.
Save Fingercomp/13c0add5e0bbeeac7fa90730172f7277 to your computer and use it in GitHub Desktop.
A slick formatter for the insane
local function format(arg)
local function expand(v)
if type(v) == "string" then
return v
elseif type(v) == "table" then
return tostring(v[1])
end
error("unsupported type")
end
local function curry(f, state)
return function(v)
return f(state, v)
end
end
local function handler(state, v)
if v == nil then
return state
end
return curry(handler, state .. expand(v))
end
return handler("", arg)
end
local myVar = 42
local bold = "{bold marker}"
print(format "myVar = " {myVar} "; " {bold} "bold, if not daring" ())
--> myVar = 42; {bold marker}bold, if not daring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment