EDK »

Console

Sandcat Browser comes with Sandcat Console, a command console with several useful commands and extension possibilities. This page explains how to extend it with custom commands. Currently, there are two methods for adding new commands, which are explained below.

Method 1: As part of a Sandcat Extension

New commands can be added using the Lua language via the console.addcmd() function during the Sandcat extension initialization or at any moment after the initialization. The first parameter must contain the command name and its arguments (if any), the second parameter the Lua code to be executed, and the third parameter must contain a simple description of the command. See below a few examples.


MyCommands = {}

function MyCommands:Google(query)
 if query ~= '' then
  browser.newtab('https://www.google.com/search?q='..query)
 end
end

function MyExtension:init()
 -- Google Search command
 console.addcmd('search [query]','MyCommands:Google(cmd.params)','Searches Google')
 -- Simple print command
 console.addcmd('say [str]','print(cmd.params)','Prints a string of text')
end

Method 2: As an external Command file

New commands can also be added by creating a Lua script file which must be placed in the Scripts/Commands directory. The first line of the script must be a comment containing the command name and its arguments (if any). The second line should contain a simple description of the command. See below an example of a command file.

say.lua:


-- say [str]
-- Prints a string of text
if cmd.params ~= '' then
 print(cmd.params)
end

You can also use the Selenite library (already included with Sandcat) to execute commands in a variety of languages.

See also:

Developer

Language

Page last modified on May 29, 2013, at 08:11 AM
© 2023 Syhunt