LifeLua 21-08-2025
Documentation for LifeLua, a Lua interpreter for the PS Vita
Loading...
Searching...
No Matches
thread

Running a function at the same time as the rest of your app. More...

Detailed Description

Every function that takes a thread as its first parameter can also be called as a method, e.g. t:start() and t:wait().

local done = false
local t = thread.new(function()
io.extract("ux0:data/big.zip", "ux0:data/big") -- slow work
done = true
end)
t:start()
while not done do
draw.text(10, 10, "Extracting...", color.new(255, 255, 255))
draw.swapbuffers()
end
Warning
Threads are experimental: they share the same Lua state as the main code, so running heavy code in a thread, or using the same variables/objects from several threads at once, may crash the app. Keep thread functions simple.

Functions

thread thread.new (function func, string name)
 
nil thread.start (thread thread)
 
nil thread.wait (thread thread)
 
nil thread.waitcb (thread thread)
 
nil thread.exit ()
 
nil thread.exitdelete ()
 

Function Documentation

◆ thread.exit()

nil thread.exit ( )

Ends the thread that calls it. Call it from inside a thread function to stop it early.

◆ thread.exitdelete()

nil thread.exitdelete ( )

Ends the thread that calls it and frees its resources. Call it from inside a thread function to stop it early.

◆ thread.new()

thread thread.new ( function func,
string name )

Creates a new thread. It doesn't run until you call thread.start().

Parameters
funcThe function the thread will run
nameName of the thread, only useful for debugging (optional, default: "LifeLua Thread")
Returns
The new thread

◆ thread.start()

nil thread.start ( thread thread)

Starts running a thread

Method form: t:start()

Parameters
threadThe thread

◆ thread.wait()

nil thread.wait ( thread thread)

Waits until a thread has finished. The code calling this stops until then.

Method form: t:wait()

Parameters
threadThe thread

◆ thread.waitcb()

nil thread.waitcb ( thread thread)

Waits until a thread has finished, like thread.wait(), but lets system callbacks run while waiting

Method form: t:waitcb()

Parameters
threadThe thread