Task

Sandcat 4.0 adds the ability to launch Lua scripts in isolated processes. Sandcat Tasks can run independently or perform operations in an isolated tab process. The tasks can be monitored and managed from the Tasks page.

Examples

Example 1: HelloWorld

To launch a Sandcat Task, you need to use the tab:runtask() method (see the Task Object for more details about task methods). The runtask method needs a string parameter that must contain a Lua script to execute.


task.caption = 'Hello World Example'
print('Hello World!')
task.status = 'Done.'

Example 2: Passing Parameters

You can supply a JSON string as a second parameter of the runtask() method if you want to pass parameters to the Sandcat Task, which you can later read using the params table or the param*() functions. This is exemplified below.

mylauncher.lua - runs in the Sandcat Browser process:


myextension = extensionpack:new()
myextension.filename = 'Demo.scx'

function myextension:launchtask()
 local j = {}
 j.caption = 'Hello World Example'
 j.msg = 'Hello World!'
 tab:runtask(self:getfile('mytask.lua'),json.encode(j))
end

mytask.lua - runs in an isolated process:


task.caption = params.caption
print(params.msg)
task.status = 'Done.'

Example 3: Reporting Success

You can use the printsuccess() and printfailure() functions to print a line to the task log and paint the task status panel in green or red color.


task.caption = 'Demo'
print('Running...')
-- some code
printsuccess('The password is: 12345!')
print('Done.')

task.caption = 'Demo'
print('Running...')
-- some code
printfailure('Nope :(')
print('Done.')
Page last modified on November 26, 2013, at 10:54 AM
© 2023 Syhunt