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.


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!'

mytask.lua - runs in an isolated process:

task.caption = params.caption
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'
-- some code
printsuccess('The password is: 12345!')

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