move network functionality to new file
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
|
||||
bool_to_int = {[false] = 0, [true] = 1}
|
||||
|
||||
local escapes = {
|
||||
{"\\", "b"},
|
||||
{"\t", "t"},
|
||||
@@ -85,3 +87,64 @@ function array_add(array, value)
|
||||
end
|
||||
table.insert(array, value)
|
||||
end
|
||||
|
||||
function round(x)
|
||||
return math.floor(x+0.5)
|
||||
end
|
||||
|
||||
local units = {
|
||||
"uHz",
|
||||
"mHz",
|
||||
"Hz",
|
||||
"kHz",
|
||||
"MHz",
|
||||
"GHz",
|
||||
}
|
||||
function unitize(v)
|
||||
local unit = 1
|
||||
v = v*1000000
|
||||
|
||||
while v >= 1000 do
|
||||
v = v/1000
|
||||
unit = unit+1
|
||||
end
|
||||
|
||||
local s
|
||||
if v >= 100 then
|
||||
s = "" .. round(v/10)*10
|
||||
elseif v >= 10 then
|
||||
s = "" .. round(v)
|
||||
elseif v >= 1 then
|
||||
s = "" .. round(v*10)/10
|
||||
if #s == 1 then s = s .. ".0" end
|
||||
else
|
||||
s = 0
|
||||
end
|
||||
|
||||
return s .. " " .. units[unit]
|
||||
end
|
||||
|
||||
function vectotable(vec)
|
||||
local tbl = {}
|
||||
for comp in string.gmatch(vec, "([^%s]+)") do
|
||||
tbl[#tbl+1] = tonumber(comp)
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
function tabletostring(table)
|
||||
local str = tostring(table[1])
|
||||
for i = 2, #table do
|
||||
str = str .. " " .. tostring(table[i])
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
function toboolean(value)
|
||||
local num = tonumber(value)
|
||||
if num == 1 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user