Difference between revisions of "Thread"

(documented how to debug threads with stack traces)
(Added concept:current.)
Line 1: Line 1:
 
{{newin|[[0.7.0]]|070|type=type}}
 
{{newin|[[0.7.0]]|070|type=type}}
 
A Thread is a chunk of code that can run in parallel with other threads.
 
A Thread is a chunk of code that can run in parallel with other threads.
 +
 +
If a Lua error occurs in the thread, a message with the name "error" gets pushed to its message pool. Retrieve the message with Thread:receive('error').
 +
 
== Constructors ==
 
== Constructors ==
{{#ask: [[Category:Functions]] [[Constructs::Thread]] [[Since::<071]]
+
{{#ask: [[Category:Functions]] [[Constructs::Thread]] [[Concept:Current]]
 
| headers=hide
 
| headers=hide
 
| default=None.
 
| default=None.
Line 8: Line 11:
 
}}
 
}}
 
== Functions ==
 
== Functions ==
{{#ask: [[Category:Functions]] [[parent::Thread||Object]] [[Since::<071]]
+
{{#ask: [[Category:Functions]] [[parent::Thread||Object]] [[Concept:Current]]
 
| headers=hide
 
| headers=hide
 
| ?Description
 
| ?Description
Line 14: Line 17:
 
== Supertypes ==
 
== Supertypes ==
 
[[Object]]
 
[[Object]]
== Notes ==
+
 
Threads will place all Lua errors in "error".
 
To retrieve the error, call thread:receive('error') in the main thread.
 
 
== See Also ==
 
== See Also ==
 
* [[parent::love.thread]]
 
* [[parent::love.thread]]

Revision as of 21:44, 20 April 2012

Available since LÖVE 0.7.0
This type is not supported in earlier versions.

A Thread is a chunk of code that can run in parallel with other threads.

If a Lua error occurs in the thread, a message with the name "error" gets pushed to its message pool. Retrieve the message with Thread:receive('error').

Constructors

love.thread.newThreadCreates a new Thread from a filename, string or FileData object containing Lua code.

Functions

Object:releaseImmediately destroys the object's Lua reference.
Object:typeGets the type of the object as a string.
Object:typeOfChecks whether an object is of a certain type.
Thread:demandReceive a message from a thread. Wait for the message to exist before returning.
Thread:getGet a value.
Thread:getErrorRetrieves the error string from the thread.
Thread:getKeysReturns the names of all messages as a table.
Thread:getNameGet the name of a thread.
Thread:isRunningReturns whether the thread is currently running.
Thread:killForcefully terminate the thread.
Thread:peekReceive a message from a thread, but leave it in the message box.
Thread:receiveReceive a message from a thread.
Thread:sendSend a message.
Thread:setSet a value.
Thread:startStarts the thread.
Thread:waitWait for a thread to finish.

Supertypes

Object

See Also

Other Languages