poppy-server/utils.lua

60 lines
1.3 KiB
Lua
Raw Permalink Normal View History

2022-01-01 07:52:02 +00:00
local tempTable = {}
2022-01-01 01:32:52 +00:00
function tempTable.unit(...)
local args = { ... }
local string = args[1]
2022-07-03 18:31:03 +00:00
assert(string, "No args to unit!")
2022-01-01 01:32:52 +00:00
for i=2, #args do
--print(type(string) .. "with" .. type(args[i]))
2022-01-02 17:40:30 +00:00
string = string .. string.char(31) .. args[i]
2022-01-01 01:32:52 +00:00
end
return string
end
2022-01-02 17:40:30 +00:00
function tempTable.resolve(record)
local tTable = {}
for entry in record:gmatch("[^\31]+") do
table.insert(tTable, entry)
end
return tTable
end
2022-01-09 09:46:42 +00:00
function tempTable.clean(record)
assert(type(record) == "string")
return record:gsub("\31", "")
end
function tempTable.pprint(record)
local cleaned, _ = record:gsub("\31","|")
return cleaned
2022-01-09 09:46:42 +00:00
end
function tempTable.nextIntRecord(record)
local nextR = tempTable.clean(record:match("^.-\31"))
record = record:gsub("^.-\31","")
return tonumber(nextR), record
end
function tempTable.nextStringRecord(record)
local nextR = tempTable.clean(record:match("^.-\31"))
record = record:gsub("^.-\31","")
return nextR, record
end
function tempTable.getIntRecords(number, record)
local tTable = {}
local nextR
for i = 1, number -1 do
2022-01-09 15:36:39 +00:00
nextR, record = tempTable.nextIntRecord(record)
2022-01-09 09:46:42 +00:00
table.insert(tTable, nextR)
end
local last = tempTable.clean(record:gsub("^.-\31",""))
table.insert(tTable, tonumber(last))
return unpack(tTable)
end
2022-01-01 01:32:52 +00:00
return tempTable