LuaTaskSystem Class

Task system to execute potentially long-running Lua script in parallel.

This object can be used in any supported language. Tasks can be passed any number of input values and return any number of output values.

# Execute a long running Lua task from python
import gs

lts = gs.LuaTaskSystem()
lts.Start(1)  # use a single worker thread

task = lts.PrepareTask("""
-- retrieve the task input values
local a, b, c = ...

-- compute results
local r1 = a * b + c
local r2 = a * c + b

-- sleep for a good 3 seconds

-- return the computed values
return r1, r2

hnd = lts.RunTask(task, (6, 5, 4))

while hnd.GetState() != gs.LuaTaskHandle.TaskComplete:

results = hnd.GetResults()

print('Received results from the Lua task: r1 = %d, r2 = %d' % (results[0], results[1]))


Member Functions

LuaTaskPrepareTask(string source)
LuaTaskHandleRunTask(LuaTask task, int arg_count, TypeValue args)
boolStart(int worker_count= 0)

Member Function Documentation

int GetWorkerCount()
Return the number of worker thread on the system.
LuaTask PrepareTask(string source)
Prepare a task to be executed on the task system.
LuaTaskHandle RunTask(LuaTask task, int arg_count, TypeValue args)
Run a task on the first available worker thread.
bool Start(int worker_count= 0)
Start the thread pool with the specified number of worker thread. Each worker thread uses its own dedicated Lua VM.
void Stop()
Stop the worker thread pool.