Added lume.trace() function

This commit is contained in:
rxi 2014-03-02 20:48:21 +00:00
parent 3324bb013c
commit fbe585fc85
2 changed files with 15 additions and 0 deletions

View File

@ -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." -- 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) ### lume.dostring(str)
Executes the lua code inside `str`. Executes the lua code inside `str`.
```lua ```lua

View File

@ -223,6 +223,13 @@ function lume.format(str, vars)
end 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) function lume.dostring(str)
return assert(loadstring(str))() return assert(loadstring(str))()
end end