You could build a string like this:
Code: Select all
-- Assuming:
x = 45
y = 56
-- Do this:
send = x.."^"..y
-- Now send = "45^56"
And then parse it like this:
Code: Select all
x = tonumber(piece(data,"^",1))
y = tonumber(piece(data,"^",2))
If you use a function "piece" like this:
Code: Select all
function piece(str,delim,num)
if num < 1 then
return ""
end
local lastEnd = 0
local matchBegin,matchEnd = string.find(str,delim,1,true)
local loop = 1
for i=2,num do
loop = i
lastEnd = matchEnd
matchBegin,matchEnd = string.find(str,delim,matchEnd+1,true)
if (matchBegin == nil) then
matchBegin = string.len(str)+1
break
end
end
if num > loop then
return ""
end
return string.sub(str,lastEnd+1,matchBegin-1)
end
You could use anything instead of "^", that's just an example. And you can put more data in there. As much as you want. The piece function is kind of wasteful if you are getting lots of data out, but it works. If you want it to be more efficient you could use a Tokenizer pattern or something.