Page 27 of 34
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 7:13 pm
by TechnoCat
I believe nested tables will require more effort on your part.
There are lots of options already though:
http://lua-users.org/wiki/TableSerialization
http://love2d.org/wiki/TLTools
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 7:49 pm
by Deif
Bambo wrote:ah i think i've got this now, im just having trouble sending a big table back with all the X,Y coords of people.
Code: Select all
connected = {
{10, 10},
{20, 20}
}
function send()
lube.bin:setseperators(string.char(30),string.char(31))
local data = lube.bin:pack( connected )
server:send(data)
end
That is basicly what i'm sending, but for some reason it doesn't allow it?
You would need to pack the {10,10} table and the {20,20} tables first with those seperators. Then pack them again using different seperators. Basically you have to turn each table into a string (which is what the packing does) and the seperators are an easy way to tell where a table begins and where a table ends so you can turn them back into tables on the other side.
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 8:32 pm
by Robin
Deif wrote:You would need to pack the {10,10} table and the {20,20} tables first with those seperators. Then pack them again using different seperators. Basically you have to turn each table into a string (which is what the packing does) and the seperators are an easy way to tell where a table begins and where a table ends so you can turn them back into tables on the other side.
TechnoCat's answer is better. What if the nesting goes even deeper? Serialization can handle those cases, just using different separators, not so much.
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 8:53 pm
by bartbes
Except this is serialization. I never claimed it was a good implementation though, quite the opposite.
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 8:59 pm
by Deif
Robin wrote:Deif wrote:You would need to pack the {10,10} table and the {20,20} tables first with those seperators. Then pack them again using different seperators. Basically you have to turn each table into a string (which is what the packing does) and the seperators are an easy way to tell where a table begins and where a table ends so you can turn them back into tables on the other side.
TechnoCat's answer is better. What if the nesting goes even deeper? Serialization can handle those cases, just using different separators, not so much.
Then change the separators again. I think making this example too complicated is going to confuse people - besides, what's the point in the library serialisation methods if people are going to use more robust methods, when in reality you're not going to be sending massively complicated nested tables across a network anyway.
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 9:10 pm
by TechnoCat
I personally find Taehl's solution to look the most elegant.
https://github.com/Taehl/TLTools
Only 21 lines! But it looks like it is incredibly easy to break with including certain characters in strings.
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 9:33 pm
by slime
For TSerial I had to change line 9 of TSerial.lua from
to
Code: Select all
if type(k) == "string" then k = string.format("[%q]", k)
, and line 13 to
Code: Select all
if type(v) == "string" then v = string.format("%q", v)
for it to work with all strings.
EDIT: also, line 14 needs to be
Code: Select all
elseif type(v) == "table" then v = TSerialize(v)
instead of
Code: Select all
elseif type(v) == "table" then v = Tserialize(v)
Re: LUBE (Networking Library)
Posted: Tue May 24, 2011 10:02 pm
by bartbes
Don't you mean
Code: Select all
if type(k) == "string" then k = string.format("[%q]", k)
?
Re: LUBE (Networking Library)
Posted: Wed May 25, 2011 5:11 am
by Robin
bartbes wrote:Except this is serialization. I never claimed it was a good implementation though, quite the opposite.
Well, yeah. But I specifically meant the serialization implementation TechnoCat linked to.
Deif wrote:Then change the separators again. I think making this example too complicated is going to confuse people - besides, what's the point in the library serialisation methods if people are going to use more robust methods, when in reality you're not going to be sending massively complicated nested tables across a network anyway.
If you want more than a simple table with only string and number values, changing separators gets hairy and unwieldy quickly. Better use a library that's easy to use right away in that case.
Re: LUBE (Networking Library)
Posted: Wed May 25, 2011 4:35 pm
by Bambo
Gah, decompression doesn't seem to work
Code: Select all
local compressed = data -- this is the compressed table
local decompressed = TLibCompress.DecompressLZW(data)
tablei = loadstring(decompressed)()