mirror of
https://github.com/TangentFoxy/lume.git
synced 2025-10-02 15:22:30 +00:00
Added lume.uuid(), tests and README.md section
This commit is contained in:
@@ -291,6 +291,10 @@ Executes the lua code inside `str`.
|
|||||||
lume.dostring("print('Hello!')") -- Prints "Hello!"
|
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)
|
### lume.hotswap(modname)
|
||||||
Reloads an already loaded module in place, allowing you to immediately see the
|
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
|
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
|
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)
|
function lume.hotswap(modname)
|
||||||
local oldglobal = lume.clone(_G)
|
local oldglobal = lume.clone(_G)
|
||||||
local updated = {}
|
local updated = {}
|
||||||
|
@@ -371,6 +371,12 @@ tests["lume.dostring"] = function()
|
|||||||
testeq( lume.dostring([[return 12345]]), 12345 )
|
testeq( lume.dostring([[return 12345]]), 12345 )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
tests["lume.uuid"] = function()
|
||||||
|
testeq( type(lume.uuid()), "string" )
|
||||||
|
testeq( #lume.uuid(), 36 )
|
||||||
|
end
|
||||||
|
|
||||||
-- lume.hotswap
|
-- lume.hotswap
|
||||||
tests["lume.hotswap"] = function()
|
tests["lume.hotswap"] = function()
|
||||||
local ok, err = lume.hotswap("bad_module_name")
|
local ok, err = lume.hotswap("bad_module_name")
|
||||||
|
Reference in New Issue
Block a user