Sending nested tables over channels

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Sending nested tables over channels

Post by Dantevg » Mon Jan 23, 2017 4:01 pm

Maybe this is a stupid question, but why aren't we able to send nested tables over channels? Is it impossible or very hard to make?
Is there a solution to send nested tables over channels? Serializing? Repeated channel sends?

EDIT: I want to send something like this:

Code: Select all

local t = {
  { type = "foo", "data", "more data", "and more", ... },
  { type = "bar", "data", "data 2", "data 3", ... },
  ...
}

User avatar
Nixola
Inner party member
Posts: 1937
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Sending nested tables over channels

Post by Nixola » Mon Jan 23, 2017 4:28 pm

Either repeated channel sends or serializing; I personally chose the former. I basically send a number (the number of tables the table contains) followed by each table sent separately.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

User avatar
bartbes
Sex machine
Posts: 4943
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Sending nested tables over channels

Post by bartbes » Mon Jan 23, 2017 6:36 pm

It's a trade-off. Full duplication is error-prone, more expensive, and often overkill. If you do want to send nested tables, you can use any kind of serialization that suits your situation. Serialization code that only supports tables without cyclic references can be much simpler and faster than code that does have to support those, for instance.

User avatar
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Re: Sending nested tables over channels

Post by Dantevg » Tue Jan 24, 2017 2:09 pm

bartbes wrote:Serialization code that only supports tables without cyclic references can be much simpler and faster than code that does have to support those, for instance.
What are cyclic references? A table referencing itself? Is that even possible in lua?

User avatar
raidho36
Party member
Posts: 1685
Joined: Mon Jun 17, 2013 12:00 pm

Re: Sending nested tables over channels

Post by raidho36 » Tue Jan 24, 2017 2:26 pm

Dantevg wrote:Is that even possible in lua?
Why wouldn't it be?

Code: Select all

local a = { }
local b = { }
a.b = b
b.a = a

User avatar
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Re: Sending nested tables over channels

Post by Dantevg » Tue Jan 24, 2017 3:16 pm

raidho36 wrote:Why wouldn't it be?

Code: Select all

local a = { }
local b = { }
a.b = b
b.a = a
Okay, that's simple indeed, now I get it.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Sending nested tables over channels

Post by Robin » Sun Jan 29, 2017 10:25 pm

If I may do some shameless self-promotion, you can use bitser to send data over channels. Bitser is both flexible and really fast.
Help us help you: attach a .love.

User avatar
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Re: Sending nested tables over channels

Post by Dantevg » Tue Jan 31, 2017 9:44 am

Something related: Why do all the channel functions accept flat tables, but the channel.peek() function doesn't?

EDIT: Bitser may be really helpful if I get stuck on this problem

User avatar
zorg
Party member
Posts: 2434
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Sending nested tables over channels

Post by zorg » Tue Jan 31, 2017 9:53 am

Dantevg wrote:Something related: Why do all the channel functions accept flat tables, but the channel.peek() function doesn't?
Even if the wiki page states this, did you try it yourself? I mean, logically, it should also support them. And if it does, then the article needs to be fixed, it's that simple.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

User avatar
bartbes
Sex machine
Posts: 4943
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Sending nested tables over channels

Post by bartbes » Tue Jan 31, 2017 10:06 am

Dantevg wrote:Something related: Why do all the channel functions accept flat tables, but the channel.peek() function doesn't?
Because peek doesn't send stuff?

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests