LUBE (Networking Library)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: LUBE (Networking Library)

Post 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
Deif
Prole
Posts: 12
Joined: Sun Mar 06, 2011 10:01 pm

Re: LUBE (Networking Library)

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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.
Help us help you: attach a .love.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by bartbes »

Except this is serialization. I never claimed it was a good implementation though, quite the opposite.
Deif
Prole
Posts: 12
Joined: Sun Mar 06, 2011 10:01 pm

Re: LUBE (Networking Library)

Post 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.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: LUBE (Networking Library)

Post 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.
Last edited by TechnoCat on Tue May 24, 2011 10:12 pm, edited 1 time in total.
User avatar
slime
Solid Snayke
Posts: 3147
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: LUBE (Networking Library)

Post by slime »

For TSerial I had to change line 9 of TSerial.lua from

Code: Select all

if type(k) == "string" then k = k
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)
Last edited by slime on Tue May 24, 2011 10:09 pm, edited 2 times in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post by bartbes »

Don't you mean

Code: Select all

if type(k) == "string" then k = string.format("[%q]", k)
?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: LUBE (Networking Library)

Post 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.
Help us help you: attach a .love.
Bambo
Prole
Posts: 41
Joined: Thu Mar 24, 2011 8:23 pm
Location: Warrington, England
Contact:

Re: LUBE (Networking Library)

Post by Bambo »

Gah, decompression doesn't seem to work :x

Code: Select all

		
		local compressed = data                                      -- this is the compressed table
		local decompressed = TLibCompress.DecompressLZW(data)            
		tablei = loadstring(decompressed)()
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 0 guests