Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function postprocessing(toProcess)
- local parameters = {}
- for index, value in ipairs(toProcess) do
- if tonumber(value) ~= nil then
- table.insert(parameters, tonumber(value))
- elseif textutils.unserialize(value) ~= nil then
- table.insert(parameters, textutils.unserialize(value))
- else
- table.insert(parameters, value)
- end
- end
- return parameters, #parameters
- end
- function deserialize(message)
- local position = 1
- local parameters = {}
- while true do
- local colonPos = string.find(message, ":", position)
- if colonPos == nil then
- table.insert(parameters, string.sub(message,position))
- break
- else
- table.insert(parameters, string.sub(message,position, colonPos-1))
- end
- position = colonPos+1
- end
- return postprocessing(parameters)
- end
- function serialize(...)
- local encodedString = ""
- for index, value_original in ipairs(arg) do
- local value = value_original
- if type(value) == "number" then
- value = tostring(value_original)
- elseif type(value) == "table" then
- value = textutils.serialize(value_original)
- end
- if type(value) ~= "string" then
- error("serialize() expects either strings, numbers, or tables")
- end
- if index == 1 then
- encodedString = value
- else
- encodedString = encodedString..":"..value
- end
- end
- return encodedString
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement