BlowTorch - DRAFT version 1
Lua Functions

Table of Contents

Common Functions

GetActionBarHeight

Executes a script that has been loaded during the plugin parsing phase.

Full Signature
GetActionBarHeight()
Parameters
none
Returns
number the height of the ActionBar, 0 if running on Android 2.3 or lower.
Example
barHeight = GetActionBarHeight()

GetDisplayDensity

Executes a script that has been loaded during the plugin parsing phase.

Full Signature
GetActionBarHeight()
Parameters
none
Returns
number the height of the ActionBar, 0 if running on Android 2.3 or lower.
Example
barHeight = GetActionBarHeight()

GetExternalStorageDirectory

Get the current external storage volume directory. Checks if the volume exists, but not if it is write protected.

Full Signature
GetExternalStorageDirectory()
Parameters
none
Returns
string the absolute path to the root of the external storage directory.
nil if there is no current external storage volume available.
Example
path = GetExternalStorageDirectory()
Note
Equivalent Lua code
Environment = luajava.bindClass("android.os.Environment")
local path = nil
if(Environment:getExternalStorageState() == Environment.MEDIA_MOUNTED) then
   path = Environment:getExternalStorageDirectory():getAbsolutePath()
else
   if(Environment:getExternalStorageState() == Environment.MEDIA_MOUNTED_READ_ONLY) then
      path = Environment:getExternalStorageDirectory():getAbsolutePath()
      Note("alert: external storage is read only!")
   end
end

GetPluginID

Gets the plugin ID associated with this plugin.

Full Signature
GetPluginID()
Parameters
none
Returns
string the id that has been assigned to this plugin.
Example
id = GetPluginID()

GetPluginName

Gets the plugin name associated with this plugin.

Full Signature
GetPluginName()
Parameters
none
Returns
string the name of this plugin.
Example
name = GetPluginName()

GetPluginInstallDirectory

Get the absolute path to the path that the plugin was loaded from.

Full Signature
GetPluginInstallDirectory()
Parameters
none
Returns
string the absolute path to where the plugin was loaded
Example
path = GetPluginInstallDirectory()
Note
This function should always return the path if the path no longer exists to the external volume being unmounted etc.

GetStatusBarHeight

Gets the current height of the status bar.

Full Signature
GetStatusBarHeight()
Parameters
none
Returns
number the size of the status bar, will always be constant regardless of the full screen state.
Example
height = GetStatusBarHeight()

Note

This is the basic linkage between Lua and the Console. The function will echo the parameter string to the main window.

Full Signature
Note(text)
Parameters
textThe text to echo back
Returns
nothing
Example
Note("Example text!")

SendToServer

Send the given string to the server.

Full Signature
SendToServer(str)
Parameters
strstring the data to send to the server
Returns
nothing
Example
SendToServer("run north;open door")
Note
This is the same as sending data from the keyboard. The data is processed for special commands and aliases.

Service Functions

AppendLineToWindow

Sends a packet of GMCP data to the server

Full Signature
AppendLineToWindow(line,windowName)
Parameters
linecom.offsetnull.bt.window.TextTree$Line the line to append, this usually comes from a trigger callback
Returns
none
Example
function calledFromTrigger(line,number,map)
   AppendLineToWindow(line,GetPluginID().."_chat_window")
end

AppendWindowSettings

Attaches a settings group from a window to the plugin settings block. This is to allow a plugin writer to include window settings in the main options dialog block at their discretion.

Full Signature
AppendWindowSettings(name)
Parameters
namestring the line to append, this usually comes from a trigger callback
Returns
none
Example
function OnBackgroundStartup()
   AppendWindowSettings(GetPluginID().."_chat_window")
end

CallPlugin

Calls a named global function in another plugin.

Full Signature
CallPlugin(name,function,arguments[,...])
Parameters
namestring the line to append, this usually comes from a trigger callback
functionfunction the global function to call.
argumentsa list of arguments to provide, can be more than one separated by commas. Numbers or strings.
Returns
none
Example
CallPlugin("button_window","newbutton",400,800,299,894)
Note
use PluginSupports to test to see if a plugin has a global function with the desired name.

DeleteTrigger

Deletes a trigger.

Full Signature
DeleteTrigger(name)
Parameters
namestring the the trigger to delete
Returns
none
Example
DeleteTrigger("mob_alert_1")

DeleteTriggerGroup

Deletes an entire group of triggers.

Full Signature
DeleteTriggerGroup(name)
Parameters
namestring the name of the trigger group to delete.
Returns
none
Example
DeleteTriggerGroup("campaign_targets")

EnableTriggerGroup

Sets the enabled state for all triggers in a group.

Full Signature
EnableTriggerGroup(name,state)
Parameters
namestring Name of the trigger group to manipulate.
stateboolean Enabled state for the group's triggers.
Returns
none
Example
EnableTriggerGroup("auto_hunt")

ExecuteScript

Executes a script that has been loaded during the plugin parsing phase.

Full Signature
ExecuteScript(name)
Parameters
namename of the script to run, this is configured in the plugin settings.
Returns
none
Example
ExecuteScript("parseInventory")

GetWindowTokenByName

Gets the raw /c com.offsetnull.bt.service.WindowToken object that is being held by the background service. This is to allow direct manipulation of the buffer.

Full Signature
GetWindowTokenByName(name)
Parameters
namestring the id of the window to get.
Returns
none
Example
window = GetWindowTokenByName(GetPluginID().."_chat_window")

InvalidateWindowText

Invalidates a foreground windows text and forces it to redraw.

Full Signature
InvalidateWindowText(name)
Parameters
namestring the name of the window to redraw
Returns
none
Example
InvalidateWindowText(GetPluginID().."_chat_window")

GetPluginSettings

Gets the raw com.offsetnull.bt.service.settings.SettingsGroup settings, this is to allow direct manipulation.

Full Signature
InvalidateWindowText(name)
Parameters
none
Returns
a com.offsetnull.bt.service.settings.SettingsGroup object that can be directly manipulated.
Example
settings = GetPluginSettings()

NewTrigger

Makes a new trigger with the given parameters

Full Signature
NewTrigger(name,pattern,config[,action,...])
Parameters
namestring name of the new trigger.
patternstring the pattern to use
configtable Configuration of the trigger options like, regex, fireOnce, etc. see example.
actiontable representing response actions to perform when triggered. May have as many as desired, see example.
Returns
none
Example
--configuration parameters is a table that can have the following properties defined:
--regex = [boolean] indicates use of regular expression or literal text.
--group = [string] group name to enroll this trigger into.
--fireOnce = [boolean] indicates whether this trigger is a one shot trigger.
--notification action table configuration can have the following properties
--{
-- type="notification", (must be set for the action type)
-- title = [string], title of the notification
-- message = [string], long message of the notification
-- soundpath = [string/boolean/nil], absolute path to the sound file to play for this notification. 
-- if nil/not set it will play the default sound. if set to false it won't play sound.
-- vibrate = [number], vibrate pattern to use, 0=short, 1=medium, 2=long, 3=super long
-- spawnNew = [boolean], indicates whether to spawn a new notification.
--}      

--toast action table configuration
--{
-- type = "toast", (must be set for the action type)
-- message = [string], message to display
-- duration = [number], 0 = short duration, 1 = long duration.
--}

--send action table configuratio
--{
-- type = "send", (must be set for the action type)
-- text = [string] text to send to the server.
--}

--gag action table configuration
--{
-- type = "gag"
-- output=[boolean], gag from output
-- log = [boolean], gag from log
-- retarget = [string] window to send this gagged line to.
--}

--replace action table configuration
--{
-- type = "replace", (must be set for the action type).
-- text = [string] text to replace matched text with.
--}

--color action table configuration
--{
-- type = "color", (must be set for the action type).
-- foreground = [number], 1-256 indicating the foreground xterm256 color to use.
-- background = [number], 1-256 indicating the background xterm256 color to use.
--}
--simple notification
NewTrigger("tmp", "^foo\.$", 
   { regex = true,group = "test", fireOnce = false }, 
   { type = "notification", title="custom title", message="custom message", vibrate = 2 })
--literal trigger with colorize and response to the server.
NewTrigger("tmp2", "fox", { regex = false },
   { type = "color", foreground = 36, background = 75},
   { type = "send", text = "listen fox" })

NewWindow

Makes a new window with the given paramters.

Full Signature
NewWindow(name,x,y,width,height,script)
Parameters
namestring name or id of the window
xnumber the x coordinate of the window
ynumber the y coordinate of the window
widthnumber the width of the window
heightnumber the height of the window
scriptstring the named script to load into the window's Lua state.
Returns
none
Example
NewWindow("chat_window",0,0,400,400,"chat_script")
Note
Windows don't work like this anymore. I'm pretty sure this won't work as intended or it will work but the size arguments will all be ignored.

PluginSupports

Checks whether a plugin has a global function of a desired name.

Full Signature
PluginSupports(name,function)
Parameters
namestring the name of the plugin to interrogate.
functionstring the name of the global function to be checked.
Returns
none
Example
if(PluginSupports("button_window","exportButtons")) then
   CallPlugin("button_window","exportButtons")
end

ReloadSettings

Causes the BlowTorch core to dump the current settings and reload them from the source files.

Full Signature
ReloadSettings()
Parameters
none
Returns
none
Example
ReloadSettings()

RegisterSpecialCommand

Adds and entry into the "special command" processor, or .nameyouwant and it will call the specified global function

Full Signature
RegisterSpecialCommand(sortName,callbackName)
Parameters
shortNamestring short name that will be searched for
callbackNamestring the name of a global function to call when this is called.
Returns
none
Example
function goHome(args)
   SendToServer("enter portal")
end
RegisterSpecialCommand("home","goHome")
Note
The callback, called when the command is processed, gives the arguments as a single string to the callback function.

SaveSettings

Initiates the saving of the whole settings wad for the currently open connection.

Full Signature
  SaveSettings()
Parameters
none
Returns
none
Example
  SaveSettings()
Note
the callback that is called when the command is processed will give the arguments as a single string to the callback function.

SimulateInput

Simulates incoming data from the server. Will be processed for triggers but not for telnet data (although it probably should).

Full Signature
  SimulateInput(data)
Parameters
datastring the data to simulate
Returns
note
Example
  SimulateInput("\n[this looks like a prompt]->\n")

Send_GMCP_Packet

Sends a packet of GMCP data to the server

Full Signature
Send_GMCP_Packet(str)
Parameters
strstring the data to send, more in the GMCP documentation.
Returns
note
Example
Send_GMCP_Packet("core.hello foo")

TriggerEnabled

Sets or Tests the enabled state of a trigger

Full Signature
TriggerEnabled(name[,state])
Parameters
namestring the trigger to test or manipulate
stateboolean the new enabled state
Returns
Returns the enabled state of the trigger if state is nil. If state is set to true or false, will return true if the state was successfully changed.
Example
if(TriggerEnabled("afk")) then
   TriggerEnabled("afk",false)
end

UserPresent

Call to get a boolean indicating if the screen is on / user present.

Full Signature
UserPresent()
Parameters
none
Returns
boolean true if the user is present, false if not
Example
present = UserPresent()

WindowBuffer

Instructs a named window to either start or stop buffering incoming text

Full Signature
WindowBuffer(name,state)
Parameters
namestring the name of the window to affect
stateboolean the state of the buffering desired
Returns
nothing
Example
WindowBuffer(GetPluginID().."_chat_window",false)

WindowXCallB

Sends a message to a foreground window that it should run a specified callback with the desired argument data.

Full Signature
WindowXCallB(name,data)
Parameters
namestring the global callback in the window to call
datastring the data to send
Returns
nothing
Example
WindowXCallB(GetPluginID().."_chat_window",42)
Note
Semantically this is the same as WindowXCallS, only great care has been taken to ensure that the data that is ferried across the AIDL bridge and delivered to the foreground window's Lua state as an array of bytes without having any intervention by the DalvikVM host converting it through a Java string to avoid corruption. This is largely to support large data tables being serialized with libmarshal or any other binary serialization format.

WindowXCallS

Sends a message to a foreground window that it should run a specified callback with the desired argument data.

Full Signature
WindowXCallS(name,data)
Parameters
namestring the global callback in the window to call
datastring the data to send
Returns
nothing
Example
WindowXCallS(GetPluginID().."_chat_window",42)
Note
Semantically this is the same as WindowXCallB, only the data is cross converted to a DalvikVM string through the AIDL bridge. This can cause some problems with binary data. For very large serialized tables, or any kind of binary data, see WindowXCallB.

Window Functions

AddOptionCallback

Add a top level menu item that will call a global function when pressed.

Full Signature
AddOptionCallback(functionName,menuText,iconDrawable)
Parameters
functionNamestring value of the function name that will be called when the menu item is pressed.
menuTextstring value that will appear on the menu item.
iconDrawableandroid.graphics.drawable.Drawable the drawable resource that will be used for the icon.
Returns
nothing
Example with no icon
AddOptionCallback("functionName","Click Me!",nil)
Example with icon
drawable = luajava.newInstance("android.drawable.BitmapDrawable",context:getResources(),"/path/to/image.png")
function menuClicked()
   Note("Menu Item Clicked!")
end

AddOptionCallback("menuClicked","Click Me!",drawable)

CancelCallback

Cancel a scheduled call made with ScheduleCallback.

Note
This will cancel all pending callbacks with the given identifier.
Full Signature
CancelCallback(id)
Parameters
idnumber the callback id to cancel
Returns
nothing
Example
CancelCallback(100)

CloseOptionsDialog

Closes the Options dialog if it is currently open.

Full Signature
CloseOptionsDialog()
Parameters
none
Returns
nothing
Example
CloseOptionsDialog()

GetActivity

Get a handle to the current Activity that is hosting the foreground window process.

Full Signature
GetActivity()
Parameters
none
Returns
android.app.Activity the current Activity that is hosting the foreground processes.
Example
activity = GetActivity()

GetOptionValue

Gets an option value by key from the parent plugin's option table.

Full Signature
  GetOptionValue(key)
Parameters
keyunique key for the option given.
Returns
The value of the option, this could be a string, number or boolean, lists will return the ordinal of the selected value.
Example
  value = GetOptionValue("input_mode")

IsStatusBarHidden

Gets the state of the status bar.

Full Signature
IsStatusBarHidden()
Parameters
none
Returns
bool true if the status bar is hidden (full screen), false if the status bar is being shown (non full screen)
Example
if(IsStatusBarHidden()) then
 Note("status bar hidden")
else
 Note("status bar not hidden")
end

PluginXCallS

Calls a function in the parent plugin's Lua state. Provides one way signaling across the AIDL bridge to the plugin host running in the background.

Full Signature
PluginXCallS(functionName,data)
Parameters
functionNamestring the global function in the plugin's host Lua state.
datastring the data to pass as a argument to the given function
Returns
nothing
Example
PluginXCallS("saveData","300")
Note
Tables can be serialized to a string and reconstituted in the plugin using loadstring(...) but the performance may suffer if the tables are large. See PluginXCallB for a slightly faster method of communication that doesn't involve the heavy Java string manipulation.

PopMenuStack

Removes the current menu item and returns the menu stack to its previous state.

Full Signature
PopMenuStack()
Parameters
none
Returns
nothing
Example
PopMenuStack()
See Also
PushMenuStack

PushMenuStack

Starts the creating of a new menu object, providing a global function name to call that will handle weather or not the back button is pressed while the menu stack is active. After this function is called, the PopulateMenu entry point will be called when the operating system has created the new menu to show.

Full Signature
PushMenuStack(callbackName)
Parameters
\bstring the name of a global function to call if the back button is pressed to cancel the menu.
Returns
nothing
Example
function PopulateMenu(menu)
 menu:addItem(0,1,1,foo)
end
PushMenuStack("menuBackPressed")

function menuBackPressed()
   PopMenuStack()
end
See Also
this relies largely on the Android Menu and MenuItem classes, please refer to the documentation and other menu related sample code.

ScheduleCallback

Add a top level menu item that will call a global function when pressed.

Full Signature
ScheduleCallback(id,callbackName,delayMillis)
Parameters
idnumber unique identifier associated with this event, will be passed to the callback.
callbackNamestring name of the global function to call after the desired elapsed time.
delayMillisdumber how long in milliseconds to delay the execution of the callback
Returns
nothing
Example
function delayCallback(id)
 Note(string.format("event %d fired.",id))
end

ScheduleCallback(100,"delayCallback",3000)
ScheduleCallback(104,"delayCallback",5000)

PluginInstalled

Checks whether a plugin is installed.

Full Signature
PluginInstalled(name)
Parameters
namethe plugin name to test.
Returns
boolean whether or not the plugin is installed.
Example
if(PluginInstalled("button_window")) then
   WindowCall("button_window","clearButtons")
end

WindowBroadcast

Calls a named global function in every window (if the window has defined it).

Full Signature
WindowBroadcast(function,arg)
Parameters
functionthe function to call.
argstring a string or number to provide to the function as an argument.
Returns
nothing
Example
WindowBroadcast("adjustZOrder","now")

WindowCall

Calls a named global function on the target window.

Full Signature
WindowCall(name,function,arg)
Parameters
namestring the name of the window to target.
functionthe function to call.
argstring a string or number to provide to the function as an argument.
Returns
nothing
Example
WindowCall("button_window","loadButtonSet","default")
See Also
WindowSupports to test whether or not it has a global function of a desired name.

WindowSupports

Tests whether a named global function exists in the target window.

Full Signature
WindowSupports(name,function)
Parameters
namestring the name of the window to target.
functionthe function to test.
Returns
boolean true if the window has a global function named function, false if not.
Example
if(WindowSupports("button_window","clearButtons")) then
   WindowCall("button_window","clearButtons")
end