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
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Sending nested tables over channels

Post by zorg »

bartbes wrote:
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?
That only means that peek doesn't have any arguments to it, which wasn't the question (albeit it was worded badly);
[wiki]Channel:peek[/wiki] The value of the message can be a boolean, string, number or a LÖVE userdata. It returns nil if there's no message in the queue.
This text is missing the "flat table" part, implying to some, that you can't peek (at) a flat table, if it was put into a channel.
I can't test this atm, but as i wrote before, logically, this should be a documentation issue.
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
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Re: Sending nested tables over channels

Post by Dantevg »

I know the usage of the channel functions. I had already tried it, of course, because it seems so unlogical. When I try to receive a flat table with channel:peek(), it just doesn't receive it. It really doesn't work.
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 »

That seems unlikely.. are you sure it's not something else? The code used in peek and pop is almost identical.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Sending nested tables over channels

Post by s-ol »

definietely does work:

Code: Select all

a = love.thread.newThread [[
  chan = love.thread.getChannel("test")
  val = chan:demand()
  chan:push(val)
]]
a:start()
chan = love.thread.getChannel("test")
chan:push({ a=1, b=2 })
function love.update()
  print(chan:peek().a, chan:peek().b)
end

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
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 »

That's strange... I thought channel:pop() was describable as:

Code: Select all

data = channel:peek()
channel:pop()
Or am I missing something here? In my code it doesn't work...

EDIT: So, the wiki was wrong, thanks for editing!
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Sending nested tables over channels

Post by zorg »

AFAICT the only thing that happened with the wiki was that those redundant descriptions for the Variants were removed from the Channel methods, so... yeah. Idk, s-ol showed a working example for peek; for pop, you need to assign the returned value to something, if you want to use it, it's not like love.graphics.pop that just modifies some internal state; the confusion may have come from that.
In other words, you don't even need to use peek, if you just want to get a value from a channel, use pop.
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
Dantevg
Prole
Posts: 9
Joined: Sat Nov 26, 2016 10:22 am
Location: Netherlands

Re: Sending nested tables over channels

Post by Dantevg »

Yes I know that channel:peek() is just channel:pop() but without changing the queue. But I want to make sure I don't receive any messages from myself. Or is that already taken care of by LÖVE? I thought channel:pop() did modify some internal state, the queue.
Post Reply

Who is online

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