mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-28 11:02:20 +00:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
076ca7972c | ||
|
c2311f9821 | ||
|
beced85d6b | ||
|
8a2765a41b |
16
lume.lua
16
lume.lua
@@ -7,7 +7,7 @@
|
||||
-- under the terms of the MIT license. See LICENSE for details.
|
||||
--
|
||||
|
||||
local lume = { _version = "1.3.0" }
|
||||
local lume = { _version = "1.3.1" }
|
||||
|
||||
local pairs, ipairs = pairs, ipairs
|
||||
local type, assert, unpack = type, assert, unpack or table.unpack
|
||||
@@ -34,6 +34,7 @@ local iscallable = function(x)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function lume.clamp(x, min, max)
|
||||
return x < min and min or (x > max and max or x)
|
||||
end
|
||||
@@ -344,13 +345,14 @@ end
|
||||
|
||||
|
||||
function lume.trace(...)
|
||||
local function stringify(x)
|
||||
x = (type(x) == "number") and lume.round(x, .01) or x
|
||||
return tostring(x)
|
||||
end
|
||||
local info = debug.getinfo(2, "Sl")
|
||||
local head = "[" .. info.short_src .. ":" .. info.currentline .. "] "
|
||||
print(head .. table.concat(lume.map({...}, stringify), " "))
|
||||
local t = { "[" .. info.short_src .. ":" .. info.currentline .. "]" }
|
||||
for i = 1, select("#", ...) do
|
||||
local x = select(i, ...)
|
||||
x = (type(x) == "number") and lume.round(x, .01) or (x or "nil")
|
||||
t[#t + 1] = tostring(x)
|
||||
end
|
||||
print(table.concat(t, " "))
|
||||
end
|
||||
|
||||
|
||||
|
@@ -359,11 +359,11 @@ tests["lume.trace"] = function()
|
||||
print = function(x)
|
||||
file, line, msg = x:match("%[(.-):(.-)%] (.*)")
|
||||
end
|
||||
lume.trace("Hi world", 123.456, 1)
|
||||
lume.trace("Hi world", 123.456, 1, nil)
|
||||
print = oldprint
|
||||
testeq( file:match(".lua$"), ".lua" )
|
||||
testeq( tonumber(line) ~= nil, true )
|
||||
testeq( msg, "Hi world 123.46 1" )
|
||||
testeq( file:match(".lua$"), ".lua" )
|
||||
testeq( tonumber(line) ~= nil, true )
|
||||
testeq( msg, "Hi world 123.46 1 nil" )
|
||||
end
|
||||
|
||||
-- lume.dostring
|
||||
|
Reference in New Issue
Block a user