mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Added lume.uuid(), tests and README.md section
This commit is contained in:
parent
88b428cb4d
commit
acdb58a447
@ -291,6 +291,10 @@ Executes the lua code inside `str`.
|
||||
lume.dostring("print('Hello!')") -- Prints "Hello!"
|
||||
```
|
||||
|
||||
### lume.uuid()
|
||||
Generates a random UUID string; version 4 as specified in
|
||||
[RFC 4122](http://www.ietf.org/rfc/rfc4122.txt).
|
||||
|
||||
### lume.hotswap(modname)
|
||||
Reloads an already loaded module in place, allowing you to immediately see the
|
||||
effects of code changes without having to restart the program. `modname` should
|
||||
|
11
lume.lua
11
lume.lua
@ -361,6 +361,17 @@ function lume.dostring(str)
|
||||
end
|
||||
|
||||
|
||||
function lume.uuid()
|
||||
local hex = "0123456789abcdef"
|
||||
local fn = function(x)
|
||||
local r = math.random(16) - 1
|
||||
r = (x == "x") and (r + 1) or (r % 4) + 9
|
||||
return hex:sub(r, r)
|
||||
end
|
||||
return (("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"):gsub("[xy]", fn))
|
||||
end
|
||||
|
||||
|
||||
function lume.hotswap(modname)
|
||||
local oldglobal = lume.clone(_G)
|
||||
local updated = {}
|
||||
|
@ -371,6 +371,12 @@ tests["lume.dostring"] = function()
|
||||
testeq( lume.dostring([[return 12345]]), 12345 )
|
||||
end
|
||||
|
||||
|
||||
tests["lume.uuid"] = function()
|
||||
testeq( type(lume.uuid()), "string" )
|
||||
testeq( #lume.uuid(), 36 )
|
||||
end
|
||||
|
||||
-- lume.hotswap
|
||||
tests["lume.hotswap"] = function()
|
||||
local ok, err = lume.hotswap("bad_module_name")
|
||||
|
Loading…
Reference in New Issue
Block a user