diff --git a/README.md b/README.md index 17fb766..d5c177d 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,14 @@ lume.format("Hello {a}, I hope {a} is {b}.", {a = "world", b = "well"}) -- Returns "Hello world, I hope world is well." ``` +### lume.trace(...) +Prints the current filename and line number followed by each argument separated +by a space. +```lua +-- Assuming the file is called "example.lua" and the next line is 12: +lume.trace("hello", 1234) -- Prints "[example.lua:12] hello 1234" +``` + ### lume.dostring(str) Executes the lua code inside `str`. ```lua diff --git a/lume.lua b/lume.lua index 1ccd563..8fa0eaa 100644 --- a/lume.lua +++ b/lume.lua @@ -223,6 +223,13 @@ function lume.format(str, vars) end +function lume.trace(...) + local info = debug.getinfo(2, "Sl") + local head = "[" .. info.short_src .. ":" .. info.currentline .. "] " + print(head .. table.concat(lume.map({...}, tostring), " ")) +end + + function lume.dostring(str) return assert(loadstring(str))() end