LUBE (Networking Library)
- TechnoCat
- Inner party member
- Posts: 1612
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: LUBE (Networking Library)
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
There are lots of options already though:
http://lua-users.org/wiki/TableSerialization
http://love2d.org/wiki/TLTools
Re: LUBE (Networking Library)
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.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.
That is basicly what i'm sending, but for some reason it doesn't allow it?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
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: LUBE (Networking Library)
TechnoCat's answer is better. What if the nesting goes even deeper? Serialization can handle those cases, just using different separators, not so much.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.
Help us help you: attach a .love.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: LUBE (Networking Library)
Except this is serialization. I never claimed it was a good implementation though, quite the opposite.
Re: LUBE (Networking Library)
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.Robin wrote:TechnoCat's answer is better. What if the nesting goes even deeper? Serialization can handle those cases, just using different separators, not so much.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
- Inner party member
- Posts: 1612
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: LUBE (Networking Library)
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.
Only 21 lines! But it looks like it is incredibly easy to break with including certain characters in strings.
Last edited by TechnoCat on Tue May 24, 2011 10:12 pm, edited 1 time in total.
- slime
- Solid Snayke
- Posts: 3170
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: LUBE (Networking Library)
For TSerial I had to change line 9 of TSerial.lua from to , and line 13 to for it to work with all strings.
EDIT: also, line 14 needs to be instead of
Code: Select all
if type(k) == "string" then k = k
Code: Select all
if type(k) == "string" then k = string.format("[%q]", k)
Code: Select all
if type(v) == "string" then v = string.format("%q", v)
EDIT: also, line 14 needs to be
Code: Select all
elseif type(v) == "table" then v = TSerialize(v)
Code: Select all
elseif type(v) == "table" then v = Tserialize(v)
Last edited by slime on Tue May 24, 2011 10:09 pm, edited 2 times in total.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: LUBE (Networking Library)
Don't you mean
?
Code: Select all
if type(k) == "string" then k = string.format("[%q]", k)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: LUBE (Networking Library)
Well, yeah. But I specifically meant the serialization implementation TechnoCat linked to.bartbes wrote:Except this is serialization. I never claimed it was a good implementation though, quite the opposite.
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.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.
Help us help you: attach a .love.
Re: LUBE (Networking Library)
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)()
Who is online
Users browsing this forum: Google [Bot], SiENcE and 1 guest