love.thread.getChannel

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Creates or retrieves a named thread channel.

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

© 2006–2020 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.thread.getChannel