love.thread.getChannel (Français)

Disponible depuis LÖVE 0.9.0
Ce-tte function n'est pas supporté-e par des versions plus anciennes.

Crée et récupère un channel (canal) de thread (fil d'exécution) nommé.

Fonction

Synopsis

channel = love.thread.getChannel( name )

Arguments

string name
Le nom du channel que vous désirez créer ou récupérer.

Retours

Channel channel
L'objet channel associé au nom.

Exemples

Communication entre main/thread

-- main (programme principal)
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

Voir également


Autres langues