forgot to commit openos

This commit is contained in:
2026-04-01 11:04:22 +02:00
parent 9291d81d41
commit b0afd0529e
179 changed files with 13952 additions and 0 deletions

30
data/openos/lib/uuid.lua Normal file
View File

@@ -0,0 +1,30 @@
local bit32 = require("bit32")
local uuid = {}
function uuid.next()
-- e.g. 3c44c8a9-0613-46a2-ad33-97b6ba2e9d9a
-- 8-4-4-4-12 (halved sizes because bytes make hex pairs)
local sets = {4, 2, 2, 2, 6}
local result = ""
local pos = 0
for _,set in ipairs(sets) do
if result:len() > 0 then
result = result .. "-"
end
for _ = 1,set do
local byte = math.random(0, 255)
if pos == 6 then
byte = bit32.bor(bit32.band(byte, 0x0F), 0x40)
elseif pos == 8 then
byte = bit32.bor(bit32.band(byte, 0x3F), 0x80)
end
result = result .. string.format("%02x", byte)
pos = pos + 1
end
end
return result
end
return uuid