deploy: 1c90c6cf04
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
local colorHex = {}
|
||||
|
||||
for i = 0, 15 do
|
||||
colorHex[2^i] = ("%x"):format(i)
|
||||
colorHex[("%x"):format(i)] = 2^i
|
||||
end
|
||||
|
||||
return colorHex
|
||||
@@ -1,35 +1 @@
|
||||
local errorManager = require("errorManager")
|
||||
|
||||
-- Simple type checking without stack traces
|
||||
local function expect(position, value, expectedType)
|
||||
local valueType = type(value)
|
||||
|
||||
if expectedType == "element" then
|
||||
if valueType == "table" and value.get("type") ~= nil then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if expectedType == "color" then
|
||||
if valueType == "number" and value >= 1 and value <= 32768 then
|
||||
return true
|
||||
end
|
||||
if valueType == "string" and colors[value] then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if valueType ~= expectedType then
|
||||
errorManager.header = "Basalt Type Error"
|
||||
errorManager.error(string.format(
|
||||
"Bad argument #%d: expected %s, got %s",
|
||||
position,
|
||||
expectedType,
|
||||
valueType
|
||||
))
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return expect
|
||||
Simple type checking without stack traces
|
||||
|
||||
@@ -1,71 +1,12 @@
|
||||
local floor, len = math.floor, string.len
|
||||
## utils.copy()
|
||||
|
||||
local utils = {}
|
||||
## utils.deepCopy()
|
||||
|
||||
function utils.getCenteredPosition(text, totalWidth, totalHeight)
|
||||
local textLength = len(text)
|
||||
## utils.getCenteredPosition()
|
||||
|
||||
local x = floor((totalWidth - textLength+1) / 2 + 0.5)
|
||||
local y = floor(totalHeight / 2 + 0.5)
|
||||
## utils.reverse()
|
||||
|
||||
return x, y
|
||||
end
|
||||
## utils.split()
|
||||
|
||||
function utils.deepCopy(obj)
|
||||
if type(obj) ~= "table" then
|
||||
return obj
|
||||
end
|
||||
## utils.uuid()
|
||||
|
||||
local copy = {}
|
||||
for k, v in pairs(obj) do
|
||||
copy[utils.deepCopy(k)] = utils.deepCopy(v)
|
||||
end
|
||||
|
||||
return copy
|
||||
end
|
||||
|
||||
function utils.copy(obj)
|
||||
local new = {}
|
||||
for k,v in pairs(obj)do
|
||||
new[k] = v
|
||||
end
|
||||
return new
|
||||
end
|
||||
|
||||
function utils.reverse(t)
|
||||
local reversed = {}
|
||||
for i = #t, 1, -1 do
|
||||
table.insert(reversed, t[i])
|
||||
end
|
||||
return reversed
|
||||
end
|
||||
|
||||
function utils.uuid()
|
||||
return string.format('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||
math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0xffff),
|
||||
math.random(0, 0x0fff) + 0x4000, math.random(0, 0x3fff) + 0x8000,
|
||||
math.random(0, 0xffff), math.random(0, 0xffff), math.random(0, 0xffff))
|
||||
end
|
||||
|
||||
function utils.split(str, sep)
|
||||
local parts = {}
|
||||
local start = 1
|
||||
local len = len(str)
|
||||
local splitIndex = 1
|
||||
|
||||
while true do
|
||||
local index = str:find(sep, start, true)
|
||||
if not index then
|
||||
parts[splitIndex] = str:sub(start, len)
|
||||
break
|
||||
end
|
||||
|
||||
parts[splitIndex] = str:sub(start, index - 1)
|
||||
start = index + 1
|
||||
splitIndex = splitIndex + 1
|
||||
end
|
||||
|
||||
return parts
|
||||
end
|
||||
|
||||
return utils
|
||||
Reference in New Issue
Block a user