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 »

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: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Sending nested tables over channels

Post by Nixola »

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: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Sending nested tables over channels

Post by bartbes »

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 »

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: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Sending nested tables over channels

Post by raidho36 »

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 »

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 »

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 »

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: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Sending nested tables over channels

Post by zorg »

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: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Sending nested tables over channels

Post by bartbes »

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 4 guests