mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-07-29 11:32: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.
|
-- 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 pairs, ipairs = pairs, ipairs
|
||||||
local type, assert, unpack = type, assert, unpack or table.unpack
|
local type, assert, unpack = type, assert, unpack or table.unpack
|
||||||
@@ -34,6 +34,7 @@ local iscallable = function(x)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function lume.clamp(x, min, max)
|
function lume.clamp(x, min, max)
|
||||||
return x < min and min or (x > max and max or x)
|
return x < min and min or (x > max and max or x)
|
||||||
end
|
end
|
||||||
@@ -344,13 +345,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function lume.trace(...)
|
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 info = debug.getinfo(2, "Sl")
|
||||||
local head = "[" .. info.short_src .. ":" .. info.currentline .. "] "
|
local t = { "[" .. info.short_src .. ":" .. info.currentline .. "]" }
|
||||||
print(head .. table.concat(lume.map({...}, stringify), " "))
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@@ -359,11 +359,11 @@ tests["lume.trace"] = function()
|
|||||||
print = function(x)
|
print = function(x)
|
||||||
file, line, msg = x:match("%[(.-):(.-)%] (.*)")
|
file, line, msg = x:match("%[(.-):(.-)%] (.*)")
|
||||||
end
|
end
|
||||||
lume.trace("Hi world", 123.456, 1)
|
lume.trace("Hi world", 123.456, 1, nil)
|
||||||
print = oldprint
|
print = oldprint
|
||||||
testeq( file:match(".lua$"), ".lua" )
|
testeq( file:match(".lua$"), ".lua" )
|
||||||
testeq( tonumber(line) ~= nil, true )
|
testeq( tonumber(line) ~= nil, true )
|
||||||
testeq( msg, "Hi world 123.46 1" )
|
testeq( msg, "Hi world 123.46 1 nil" )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- lume.dostring
|
-- lume.dostring
|
||||||
|
Reference in New Issue
Block a user