Difference between revisions of "love.thread.getChannel"
m |
|||
Line 10: | Line 10: | ||
=== Returns === | === Returns === | ||
{{param|Channel|channel|The Channel object associated with the name.}} | {{param|Channel|channel|The Channel object associated with the name.}} | ||
+ | == Examples == | ||
+ | === Communication between main/thread === | ||
+ | <source lang="lua"> | ||
+ | -- main | ||
+ | thread = love.thread.newThread ( "thread.lua" ); | ||
+ | thread:start (); | ||
+ | channel = {}; | ||
+ | channel.a = love.thread.getChannel ( "a" ); | ||
+ | channel.b = love.thread.getChannel ( "b" ); | ||
+ | channel.b:push ( "foo" ); | ||
+ | |||
+ | function love.update ( dt ) | ||
+ | local v = channel.a:pop (); | ||
+ | if v then | ||
+ | print ( tostring ( v ) ); | ||
+ | channel.b:push ( "foo" ); | ||
+ | end | ||
+ | end | ||
+ | |||
+ | -- thread | ||
+ | channel = {}; | ||
+ | channel.a = love.thread.getChannel ( "a" ); | ||
+ | channel.b = love.thread.getChannel ( "b" ); | ||
+ | |||
+ | while true do | ||
+ | local v = channel.b:pop (); | ||
+ | if v then | ||
+ | print ( tostring ( v ) ); | ||
+ | channel.a:push ( "bar" ); | ||
+ | end | ||
+ | end | ||
+ | </source> | ||
== See Also == | == See Also == |
Latest revision as of 21:56, 23 September 2017
Available since LÖVE 0.9.0 |
This function is not supported in earlier versions. |
Creates or retrieves a named thread channel.
Contents
Function
Synopsis
channel = love.thread.getChannel( name )
Arguments
string name
- The name of the channel you want to create or retrieve.
Returns
Channel channel
- The Channel object associated with the name.
Examples
Communication between main/thread
-- main
thread = love.thread.newThread ( "thread.lua" );
thread:start ();
channel = {};
channel.a = love.thread.getChannel ( "a" );
channel.b = love.thread.getChannel ( "b" );
channel.b:push ( "foo" );
function love.update ( dt )
local v = channel.a:pop ();
if v then
print ( tostring ( v ) );
channel.b:push ( "foo" );
end
end
-- thread
channel = {};
channel.a = love.thread.getChannel ( "a" );
channel.b = love.thread.getChannel ( "b" );
while true do
local v = channel.b:pop ();
if v then
print ( tostring ( v ) );
channel.a:push ( "bar" );
end
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info