Difference between revisions of "love.thread.getChannel"
m |
|||
(One intermediate revision by one other user not shown) | |||
Line 9: | Line 9: | ||
{{param|string|name|The name of the channel you want to create or retrieve.}} | {{param|string|name|The name of the channel you want to create or retrieve.}} | ||
=== Returns === | === Returns === | ||
− | {{param|Channel|channel| | + | {{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 == | ||
Line 15: | Line 47: | ||
* [[Constructs::Channel]] | * [[Constructs::Channel]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
− | {{#set:Description=Creates or retrieves a | + | {{#set:Description=Creates or retrieves a named thread channel.}} |
== Other Languages == | == Other Languages == | ||
{{i18n|love.thread.getChannel}} | {{i18n|love.thread.getChannel}} |
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