Functions+ Help Document

Requires latest version (v3.5.3+) - Made by /u/shirtandtieler


My motivation in creating this library was wanting to create a way to seamlessly integrate custom 
functions with AutoTouch. After many hours of hard work, I have created a whole spectrum of different 
useful functions. If you're familiar with Python, any similar naming conventions are no coincidence :)

Enjoy! (And contact me on reddit if you have any questions/problems/suggestions)

Contents

  1. FAQs
  2. Functions
    1. Checks / Logic
      1. getActiveApp
      2. isBool
      3. isNil
      4. isNotNil
      5. isNum
      6. isStr
      7. isTable
      8. isin
      9. isnotin
      10. string.startswith
      11. string.endswith
      12. tblsEqual
    2. Variable Modifiers
      1. deepcopy
      2. join
      3. merge
      4. string.format
      5. string.replace
      6. string.split
      7. string.trim
    3. Math
      1. count
      2. div
      3. len
      4. round
    4. File System
      1. copyFile
      2. fileExists
      3. formatLog
      4. getDir
      5. getFileSize
      6. getLine
      7. getLines
      8. replaceInFile
      9. search
    5. Action
      1. clear
      2. draw
      3. exe
      4. help
      5. pause
      6. print
      7. pprint
      8. scroll
    6. Conversion
      1. eval
      2. str
      3. num
      4. hexToInt
      5. hexToName
      6. hexToRgb
      7. intToHex
      8. intToName
      9. rgbToHex
      10. rgbToName
  3. xToName Color Scheme Options

Back to top 

FAQs

How to install/uninstall?

To install, just run the Functions+.lua.e script, make sure 'Install' is selected, and then select 'Confirm'! Once that's done, you're good to go :D

To uninstall, follow the same instructions as with installing - but this time, select the picker box and choose 'Uninstall'

Whats with the "string.X" functions?

These functions are modifiers to strings (i.e. quoted text).

Let's say you have the code:

 name = " shirtANDtieler!? " 

If you wanted to run one of the string.X functions, say the string.trim function, you can either do:

  •  string.trim(name)
  • OR

  •  name:trim()

And both will accomplish the same thing.

Help! X function isn't working!

A few things...

  1. Are the parameters in the correct order?

    Let's take the count function for example...

    If you wanted to count the number of 'f's in the string "fffuuuu-", you'd do:

     count("f", "fffuuuu-") 

    and not

     count("fffuuuu-", "f") 
  2. Are you sure your input is correct? (check your spelling)
  3. If none of these suggestions help, feel free to shoot me a message on reddit
Any risks in using this script?

As far as installing it goes, there are 0 risks. I have thoroughly tested the install/uninstall process dozens of times and have never encountered any problems.

In the case that the uninstall feature isn't working, just reinstall AutoTouch and it'll completely remove Functions+.

As far as using the functions go, the only function that could possibly cause some damage is exe - but that's only because you're running terminal commands. As long as you're not running commands to remove all files on your device, you'll be perfectly safe :)

What if I have a suggestion for a function or a bug to report?

For either a suggestion or a bug, shoot a message to /u/shirtandtieler on Reddit.

I'm totally open to (and would love) suggestions for new functions to add, but only if they are useful/practical -though, if you're doubting the practicality of it, still send it to me anyway :)



Functions

Back to top 

getActiveApp()

Gets the AppID of the currently active app

Parameters

Parameter Type Description
None None None

Return values

Type Description
String The full app identifier

Example(s)

  1. -- while in the AutoTouch app
  2. log(getActiveApp())
  3. -- prints 'me.autotouch.AutoTouch.ios8' to the log

Back to top 

isBool(input)

Checks if the input is a boolean

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is a boolean, otherwise false

Example(s)

  1. t = true
  2. f = false
  3. if isBool(t) and isBool(f) then
  4. log("Both variables are booleans!") -- gets logged
  5. end

Back to top 

isNil(input)

Checks if the input is nil (a.k.a. null, None, nothing, etc.)

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is nil, otherwise false

Example(s)

  1. -- example function that doesn't return anything
  2. function test(x, y)
  3. local z = x + y
  4. end
  5. set2nil = test(1, 2)
  6. if isNil(set2nil) then
  7. log("The test function returned nil!") -- gets logged
  8. else
  9. log("The test function has a return value!") -- does NOT get logged
  10. end

Back to top 

isNotNil(input)

Checks if the input is not nil

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is NOT nil, otherwise false (i.e. the input IS nil)

Example(s)

  1. -- example function that doesn't return anything
  2. function test(x, y)
  3. local z = x + y
  4. end
  5. set2nil = test(1, 2)
  6. if isNotNil(set2nil) then
  7. log("The test function has a return value!") -- does NOT get logged
  8. else
  9. log("The test function returned nil!") -- gets logged
  10. end

Back to top 

isNum(input)

Checks if the input is a number

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is a number, otherwise false

Example(s)

  1. integer = 3
  2. float = 3.14159
  3. hexadecimal = 0xbadb07
  4. if isNum(integer) and isNum(float) and isNum(hexadecimal) then
  5. log("All 3 variables are numbers!") -- gets logged
  6. end

Back to top 

isStr(input)

Checks if the input is a string (i.e. text)

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is a string (i.e. text), otherwise false

Example(s)

  1. objects = {0xca7d0e, "fat horse"}
  2. if isStr(objects[1]) then
  3. log(objects[1] .. " is a string.") -- does NOT get logged
  4. elseif isStr(objects[2]) then
  5. log(objects[2] .. " is a string!") -- gets logged
  6. end

Back to top 

isTable(input)

Checks if the input is a table (a.k.a. array, list)

Parameters

Parameter Type Description
input Any (String, Table, Number, Boolean, Nil) The object you want to check

Return values

Type Description
Boolean true if the input is a table, otherwise false

Example(s)

  1. realTable = {1, false, "hello!"}
  2. stringTable = "{true, 'ohai', 66}"
  3. if isTable(realTable) then
  4. log("realTable is a real table!") -- gets logged
  5. end
  6. if isTable(stringTable) then
  7. log("stringTable isn't a table, it's a string!") -- also gets logged
  8. end

Back to top 

isin(x,y)

Checks if x is a substring or subelement of y

Parameters

Parameter Type Description
x Any (String, Table, Number, Boolean, Nil) The substring/subelement
y Any (String, Table, Number, Boolean, Nil) The larger object that you want the function to parse

Return values

Type Description
Boolean true if x is in y, otherwise false

Example(s)

  1. -- Example 1: (String, String)
  2. if isin("o", "AutoTouch") then
  3. log("There's an 'o' in 'AutoTouch!")
  4. -- since there is an 'o' in the word 'AutoTouch', this gets logged
  5. end
  6. -- Example 2: (String, Table)
  7. itemToCheck = "baby"
  8. pets = {"dog", "cat", "bird"}
  9. if isin(itemToCheck, animals) then
  10. log("A baby is a pet too!")
  11. -- since "baby" is not in the table, this does NOT get logged
  12. end

Back to top 

isnotin(x,y)

The inverse of 'isin' - made as an easier way to type than 'not isin(,)'

Parameters

Parameter Type Description
x Any (String, Table, Number, Boolean, Nil) The substring or subelement
y Any (String, Table, Number, Boolean, Nil) The larger object that you want the function to parse

Return values

Type Description
Boolean true if x is NOT in y, otherwise false

Example(s)

  1. -- Example 1: (Number, String)
  2. birth_year = 1992
  3. birthday = "My birthday falls on August 14th"
  4. if isnotin(birth_year, birthday) then
  5. log("No details on the birth year in the birthday description text!")
  6. -- gets logged since the string '1992' is nowhere in the description
  7. end

Back to top 

string.startswith(input, starts)

A check to see if a string starts with a certain string

Parameters

Parameter Type Description
input String The string to check
starts String The possible sub-string

Return values

Type Description
Boolean true if <input> starts with <starts>, otherwise false

Example(s)

  1. diss = "You are so dumb that your dog teaches you tricks."
  2. if string.startswith(diss, "Yo mama") then
  3. log("You just got schooled by a yo-mama diss!")
  4. elseif diss:startswith("You") then
  5. log("You just got schooled with a diss on you!")
  6. -- this is what gets logged
  7. else
  8. log("Some other diss was made")
  9. end

Back to top 

string.endswith(input, ends)

A check to see if a string ends with a certain string

Parameters

Parameter Type Description
input String The string to check
ends String The possible sub-string

Return values

Type Description
Boolean true if <input> ends with <ends>, otherwise false

Example(s)

  1. diss = "You are so dumb that your dog teaches you tricks."
  2. if string.endswith(diss, "Yo mama") then
  3. log("You just got schooled by a yo-mama diss!")
  4. elseif diss:endswith("You") then
  5. log("You just got schooled with a diss on you!")
  6. -- this is what gets logged
  7. else
  8. log("Some other diss was made")
  9. end

Back to top 

tblsEqual(t1, t2)

Checks (recursively) if the two given tables are the same - Order of the given tables does not matter

Parameters

Parameter Type Description
t1 Table One of the two tables to check
t2 Table The second table to check

Return values

Type Description
Boolean true if both tables contain the same elements, otherwise false

Example(s)

  1. someRandomStuff = {1, "potato", {"jk", "!!!", 5}}
  2. sameRandomStuff = {"potato", {"jk", "!!!", 5}, 1}
  3. areSame = tblsEqual(someRandomStuff, moreRandomStuff)
  4. if areSame then
  5. log("They're the same!") -- this gets logged as order of elements does not matter
  6. end

Back to top 

deepycopy(orig)

Recursively copies/duplicates the given table so that it is separate and independent from the original

Parameters

Parameter Type Description
orig Table The table you want to make a copy of

Return values

Type Description
Table An independently copied table

Example(s)

  1. origTable = {1, "dog", {false, "cat"}}
  2. fakeCopy = origTable
  3. dupdCopy = deepcopy(origTable)
  4. -- to show the difference between the 'fakeCopy' and the 'dupdCopy'...
  5. origTable[3][1] = true -- changes the first item of the third item (i.e. false)
  6. print(origTable) -- logs: {1, "dog", {true, "cat"}}
  7. print(fakeCopy) -- logs: {1, "dog", {true, "cat"}} -- setting one variable equal to another simply makes a link
  8. print(dupdCopy) -- logs: {1, "dog", {false, "cat"}} -- whereas a deep copy remains separate/independent

Back to top 

join(...)

Concatenates folder/file paths using proper formatting

Parameters

Parameter Type Description
... 1+ String(s) The paths/names of folders/files (order matters)

Return values

Type Description
String A formatted path

Example(s)

  1. FuncPlus_File = join(rootDir(), "Functions+.lua")
  2. -- FuncPlus_File == "/var/mobile/Library/AutoTouch/Scripts/Functions+.lua"
  3. random_Image = join("var/", "/mobile/", "/Media", "DCIM", "100APPLE", "/IMG_2011.PNG")
  4. -- random_Image == "/var/mobile/Media/DCIM/100APPLE/IMG_2011.PNG"

Back to top 

merge(...)

Merges the objects into one table (if custom keys are used in inputted tables, the later items will take precendence)

Parameters

Parameter Type Description
... 0 or more objects of any type As many items as you want to be merged together

Return values

Type Description
Table A table containing all the elements given (no order guarenteed)

Example(s)

  1. two_letter_words = {"by", "if", "up"}
  2. three_letter_words = {"can", "how", "you"}
  3. X_letter_words = merge(two_letter_words, three_letter_words, "touch")
  4. -- X_letter_words == {"by", "if", "up", "can", "how", "you", "touch"}
  5. -- map letters of words to their position in the word
  6. hello = {["h"]=1, ["e"]=2, ["l"]={3,4}, ["o"]=5}
  7. world = {["w"]=1, ["o"]=2, ["r"]=3, ["l"]=4, ["d"]=5}
  8. greeting = merge(hello, world)
  9. -- greeting == {["h"]=1, ["e"]=2, ["l"]=4, ["o"]=2, ["w"]=1, ["r"]=3, ["d"]=5}
  10. -- note that the "l" and "o" keys from were replaced by the indicies of the letters in

Back to top 

string.format(input, ...)

An easier way to format a string than to use Lua's string.format function

Parameters

Parameter Type Description
input String The string to be formatted with open+closed curly brackets whereever you want one of the following variables to be inserted
... 0 or more Strings and/or Numbers "..." allows you to insert a near-infinite amount of variables. Each open+closed curly brackets will be replaced by the corresponding item

Return values

Type Description
String The formatted string

Example(s)

  1. fav_fruit = "mango"
  2. fav_vegi = "artichoke"
  3. fav_candy = "KitKat"
  4. intro = string.format("My favorite fruit is the {}, favorite vegi is the {}, and favorite candy is {}", fav_fruit, fav_vegi, fav_candy)
  5. -- intro == "My favorite fruit is the mango, favorite vegi is the artichoke, and favorite candy is KitKat"
  6. madlib = "'There are too many {} {} on this {} plane!', he screamed."
  7. verb_endIn_ing = "flip flopping"
  8. plural_noun = "fishes"
  9. adj = "drunk"
  10. madlib = madlib:format(verb_endIn_ing, plural_noun, adj)
  11. -- madlib == "'There are too many flip flopping fishes on this drunk plane!', he screamed."

Back to top 

string.replace(input, before, after, limit)

Replaces any occurances of a substring within a string

Parameters

Parameter Type Description
input String The string to replace text in
before String The string to look for within <input>
after String or nil Replaces any occurances of with this string; if set to nil, then it will simply remove the found text.
limit Number or Nil The max number of occurances to replace in <input>

Return values

Type Description
String The new string with replacements made

Example(s)

  1. tongue_twister = "peter piper picked a peck of pickled peppers"
  2. new_tongue_twister = string.replace(tongue_twister, "p", "shm")
  3. -- new_tongue_twister == "shmeter shmiper shmicked a shmeck of shmickled shmeppers"
  4. incorrect = "Young man, your going to keep your room clean, or else you're grounded!"
  5. correct = incorrect:replace("your", "you're", 1)
  6. -- correct == "Young man, you're going to keep your room clean, or else you're grounded!"

Back to top 

string.split(input, delim, autoNum)

Splits a string into a table

Parameters

Parameter Type Description
input String The item you want converted into a table
delim String The string that you want to divide the input by (Note: this gets excluded from the resulting table); If set to nil or an empty string is used, it will split by every character
autoNum Boolean true if you want the function to turn strings of numbers to the number type

Return values

Type Description
Table A table of strings (and possibly numbers)

Example(s)

  1. drinks = 'tea, coffee, water, beer'
  2. drinks_table = string.split(drinks, ", ") -- autoNum is optional
  3. -- drinks_table == {"tea", "coffee", "water", "beer"}
  4. grocery_list = "5 apples 2 oranges 8 bananas 1 mango"
  5. grocery_table = grocery_list:split(" ", true)
  6. -- grocery_table == {5, "apples", 2, "oranges", 8, "bananas", 1, "mango"}
  7. hello = "Hello"
  8. helloTable = hello:split()
  9. -- helloTable == {"H", "e", "l", "l", "o"}

Back to top 

string.trim(input)

Removes any whitespace around of a string

Parameters

Parameter Type Description
input String The string will possible whitespace at the start or end

Return values

Type Description
String A fixed version of the string without the leading/trailing whitespace

Example(s)

  1. code = " if x then y"
  2. trimmedCode = string.trim(code)
  3. -- trimmedCode == "if x then y"
  4. title = " [ HELLO ] "
  5. trimmedTitle = title:trim()
  6. -- trimmedTitle == "[ HELLO ]"

Back to top 

count(value, input)

Counts the number of occurances that appear in an object

Parameters

Parameter Type Description
value String, Number, or Boolean The item that you want counted
input Any (String, Table, Number, Boolean, Nil) Contains 0 or more instances of the value parameter

Return values

Type Description
Number The number of times 'value' appears in 'input'

Example(s)

  1. -- Example 1: (String, String)
  2. letter = "o"
  3. word = "AutoTouch"
  4. numOs = count(letter, word)
  5. -- numOs is set to 2, as there are two 'o's in the word 'AutoTouch'
  6. -- Example 2: (String, Table)
  7. drink = "Bleach"
  8. drinksHadToday = {"vodka", "water", "vodka", "coca-cola", "vodka"}
  9. poisonsConsumed = count(drink, drinksHadToday)
  10. -- set to 0, as no bleach was drunken (at least for today)

Back to top 

div(d1, d2)


Does floor division on the two values

Parameters

Parameter Type Description
d1 Number The "numerator"
d2 Number The "denominator"

Return values

Type Description
Number The most amount of times d2 can go into d1

Example(s)

  1. div(10, 2) -- results in 5
  2. div(11, 2) -- also results in 5

Back to top 

len(input)

Gets the length or size of an object

Parameters

Parameter Type Description
input Table or String The item you want to find the length/size of

Return values

Type Description
Number The length/size of <input>

Example(s)

  1. -- in Lua, you can use # before a table name to get its length
  2. -- however, this doesn't work if the indices are non-numbers
  3. -- as you'll see below, this function doesn't have that problem
  4. partOfBody = {["eyes"]="head", ["thumb"]="hand", ["butt"]="legs"}
  5. log(#partOfBody) -- logs 0, which is wrong
  6. log(len(partOfBody)) -- logs 3, which is correct
  7. item = "potato"
  8. log(len(item)) -- logs 6

Back to top 

round(num, places)

Rounds a number to specified number of places

Parameters

Parameter Type Description
num Number A number with decimal places
places Number The number of places you want to round the number to

Return values

Type Description
Number The rounded number

Example(s)

  1. pi = round(math.pi, 2)
  2. -- pi == 3.14
  3. e = round(2.71828, 0)
  4. -- e == 3

Back to top 

copyFile(srcFilePath, dstFilePath, overwrite)

Copies a file from one location to another

Parameters

Parameter Type Description
srcFilePath String The original path for the file that you want to copy
dstFilePath String The path + file name of where you want the file to be copied to
overwrite Boolean true if you want it to automatically overwrite a file if one exists at the destination, false if you want it to cancel if there's an existing file at the destination

Return values

Type Description
None None

Example(s)

  1. copyFile("/var/mobile/Downloads/script1.lua", "script1.lua")
  2. -- copies the "script1.lua" file to the AutoTouch scripts directory
  3. -- since was not given, it is set to false by default

Back to top 

fileExists(file)

Checks if a certain file or folder exists

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.

Return values

Type Description
Boolean true if the file/folder does exist, otherwise false

Example(s)

  1. if fileExists("/var/mobile/Library/AutoTouch/Library/log.log") then
  2. log("The log exists!") -- which it does, so this gets printed to the log
  3. end
  4. if fileExists("/var/mobile/fakeFolder") then
  5. log("This should not get logged....")
  6. else
  7. log("Fake folder is fake!") -- this is what gets printed to the log
  8. end

Back to top 

formatLog(option, value)

Formats the log for easier viewing 
Note: You only have to run this once. After that, anything added to the log will be in the specified format.
If you want it to go back to the default settings, run the function with no parameters (this will apply to anything logged after reverting it)

Parameters

Parameter Type Description
option String Can either be 'prefix' (or 'p') to customize the prefix of the line, 'seperator' ('sep' and 's' also work) to customize the seperation between each entry
value String What you want to be used for the specified option

Return values

Type Description
None None

Example(s)

  1. -- log.log
  2. --[[
  3. 02-11 12:18:44 Testing 1, 2, 3 ....
  4. 02-11 12:19:00 Did this pause for 16 seconds?
  5. 02-11 14:56:36 Script ran successfully!
  6. --]]
  7. editLog('p', '>')
  8. editLog('s', '*')
  9. -- log.log
  10. --[[
  11. > Testing 1, 2, 3 ....
  12. * * * * * * * * * * * * * * * * * * * *
  13. > Did this pause for 16 seconds?
  14. * * * * * * * * * * * * * * * * * * * *
  15. > Script ran successfully!
  16. --]]

Back to top 

getDir(dir)

Gets all the folders/files in specific directory

Parameters

Parameter Type Description
dir String Path of the directory you want to get the files in

Return values

Type Description
Table A list of the folder/file names

Example(s)

  1. AT_Library_Files = getDir("/var/mobile/Library/AutoTouch/Library") -- the last slash is optional
  2. print(AT_Library_Files)
  3. -- prints "{'data.sqlite3', 'license', 'log.log'}" to the log

Back to top 

getFileSize(fileName)

Gets the size of the specified file

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.

Return values

Type Description
Number The number of bytes the file is

Example(s)

  1. oneKB = getFileSize("oneKilobyteFile.lua")
  2. -- oneKB == 1024

Back to top 

getLine(file, lineNum)

Similar to getLines, but just gets one specified line

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.
lineNum Number The line that the desired text is on (starts at 1)

Return values

Type Description
String The specified line

Example(s)

  1. -- mySecrets.txt (located in /var/mobile/Documents/)
  2. --[[
  3. I have 6 toes
  4. Crosswords make me horny
  5. I ate dog food once out of curiosity
  6. --]]
  7. secret_crosswords = getLine("/var/mobile/Documents/mySecrets.txt", 2)
  8. print(secret_crosswords) -- prints "Crosswords make me horny" to the log

Back to top 

getLines(file)

Get the lines of a specified file

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.

Return values

Type Description
Table A list of each line in the file

Example(s)

  1. -- Using the "mySecrets.txt" file in the getLine example....
  2. secrets = getLines("/var/mobile/Documents/mySecrets.txt")
  3. print(secrets)
  4. -- prints "{'I have 6 toes', 'Crosswords make me horny', 'I ate dog food once out of curiosity'}" to the log

Back to top 

replaceInFile(file, before, after, limit, backup)

Replaces some text within a specified file

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can input just the name of the file.
before String The text in the file that you want replaced
after String The new text that you want to replace the old text with; set to nil or an empty string if you want to simply remove the text.
limit int Sets the number of replacements you want to be made in the file; set to nil or 0 to change every found location.
backup Boolean Whether or not you want the file to be backed up. If set to true, it will create a copy with a ".bak" extension; if left out or set to nil, it will default to true.

Return values

Type Description
None None

Example(s)

  1. -- example.lua (located in scripts directory)
  2. tap(100, 75)
  3. usleep(16000)
  4. tap(180, 200)
  5. usleep(16000)
  6. replaceInFile("example.lua", "16000", "32000", 0, false)
  7. -- example.lua now looks like:
  8. tap(100, 75)
  9. usleep(32000)
  10. tap(180, 200)
  11. usleep(32000)
  12. -- and does not create a backup

Back to top 
Searches a specified file for some text

Parameters

Parameter Type Description
file String The path/location of the target file; note that if the file is in the scripts directory, you can just input the name of the file.
query String What you want to search the target file for
startSearch Number The index of the file that you want the search to start at (starts at 1 and includes whitespaces)
endSearch Number The index of the file that you want the search to stop at

Return values

Type Description
Table A nested table, where each inner-table contains the start index and end index of the found result

Example(s)

  1. -- log.log
  2. --[[
  3. 02-12 20:31:59 Script ran successfully!
  4. 02-12 20:32:00 Script ran successfully!
  5. 02-15 12:18:36 Script ran successfully!
  6. 02-22 17:09:03 Script failed to run!
  7. 02-26 0l:46:28 Script ran successfully!
  8. --]]
  9. entries_from_feb12 = search("/var/mobile/Library/AutoTouch/Library/log.log", "02-12")
  10. print(entries_from_feb12)
  11. -- prints "{{1,5}, {41, 45}}" to the log

Back to top 

clear()

Erases the AutoTouch log

Parameters

Parameter Type Description
None None None

Return values

Type Description
None None

Example(s)

  1. -- log.log
  2. --[[
  3. 02-24 23:53:03 SUPER SECRET MESSAGE!!!
  4. --]]
  5. clear()
  6. -- log.log
  7. --[[
  8. --]]

Back to top 

draw(shape, size, centerPos)

Draws a shape on the screen

Parameters

Parameter Type Description
shape String Currently supports: square, circle, triangle
size Number The diameter in pixels
centerPos Table A table of 2 numbers dictating the X, Y coordinates to draw the shape around

Return values

Type Description
None None

Example(s)

  1. draw("circle", 20, {400, 400})
  2. -- draws a 20 pixel wide circle around x=400, y=400
  3. width, height = getScreenResolution()
  4. draw("square", width/4, {width/2, height/2})
  5. -- draws a square, with a length/width of a quarter of the width, around the center of the screen

Back to top 

exe(cmd)

Runs a specified command (Be careful when using!)

Parameters

Parameter Type Description
cmd String The command you want to run

Return values

Type Description
String The output of the command

Example(s)

  1. ip = exe("ipconfig getifaddr en0")
  2. -- ip == the user's local IP address (if connected to wifi)
  3. exe("cd /var/mobile/Downloads; mkdir YoutubeVideos")
  4. -- makes a folder called "YoutubeVideos" in the "/var/mobile/Downloads" folder

Back to top 

help(func)

Print to the log more information about a topic

Parameters

Parameter Type Description
func String If left empty, it will provide general information; If "functions" is used, it will log a list of the function names; If a string of a function name is used, it will log a plain text version of the help shown in this document.

Return values

Type Description
None None

Example(s)

  1. help() -- logs contact info and other general-info kind of stuff
  2. help("functions") -- logs a list of functions
  3. help("str") -- logs help about the function 'str'

Back to top 

pause(time, unit)

An easier way to use usleep without having to wonder if you've used enough 0s

Parameters

Parameter Type Description
time Number The number of s that you want to sleep for
unit String If left empty or nil, it will sleep for

Return values

Type Description
None None

Example(s)

  1. pause(1000000) -- pauses for 1 million microseconds, aka a second
  2. pause(1, "s") -- also pauses for 1 second

Back to top 

print(...)

Implements Lua's print function while also adding in support for tables

Parameters

Parameter Type Description
... 0 or more objects of any type The stuff you want to be printed

Return values

Type Description
None None

Example(s)

  1. print("The following", 3, "objects were found on the deceased's body:",{"keys", "a used straw", "cucumber"})

Back to top 

pprint(tabl)

Pretty prints a table to the log using indents and formatting

Parameters

Parameter Type Description
tabl Table The table to be printed

Return values

Type Description
None None

Example(s)

  1. letters2nums = {["a"]=1, ["b"]=2, ["cde"]={3,4,5}, ["f"]=6}
  2. pprint(letters2nums)
  3. --[[ logs the following:
  4. {
  5. ["a"] = 1,
  6. ["b"] = 2,
  7. ["cde"] = {
  8. 3,
  9. 4,
  10. 5
  11. },
  12. ["f"]=6
  13. }
  14. --]]

Back to top 

scroll(dir, speed, repeats)

Scrolls the screen in a cardinal direction

Parameters

Parameter Type Description
dir String One of: 'u' (up), 'd' (down), 'l' (left), or 'r' (right)
speed Number A number between 1 and 5, where 1 is the slowest and 5 is the fastest
repeats Number The number of times you want it to scroll

Return values

Type Description
None None

Example(s)

  1. scroll('d', 1)
  2. -- scrolls down (ie simulates a finger drag upwards) at a snail's pace, doing so one time

Back to top 

eval(input)

Evaluates the given input, converting it into code

Parameters

Parameter Type Description
input String The thing to be turned into code

Return values

Type Description
Varies based on input The evaluated string

Example(s)

  1. math_string = "8*3-10"
  2. answer = eval(math_string)
  3. log(answer) -- logs: 14
  4. toEval = "beersDrank = 5" -- you can set a value to a variable within the string
  5. consumed = eval(toEval) -- now both consumed and beersDrank are equal to 5
  6. log(consumed .. " / " .. beersDrank) -- logs: 5 / 5
  7. toEval:replace("5", "6", 1) -- replacing stuff in the original string will effect the outcome
  8. eval(toEval)
  9. log(beersDrank) -- now logs: 6

Back to top 

str(input)

An improved version of Lua's "tostring" which allows you to turn any object into a string (good for printing to the log)

Parameters

Parameter Type Description
input Any (String, Number, Boolean, Table, Nil) The thing to be turned into a string

Return values

Type Description
String A string-ified version of input

Example(s)

  1. log("Does " .. str(3) .. " * 2 == 6? " .. str(3*2==6))
  2. -- logs "Does 3 * 2 == 6? true"
  3. randomObjects = {"a", 14, false, "b", nil, true}
  4. log(str(randomObjects))
  5. -- logs "{'a', 14, false, 'b', nil, true}"

Back to top 

num(input)

A shorter version of Lua's tonumber

Parameters

Parameter Type Description
input String The thing to be turned into a number

Return values

Type Description
Number A number-ified version of input

Example(s)

  1. result = "5 is my answer"
  2. answer = num(result:sub(1,2))
  3. -- takes a substring of the first character to the second (doesn't include the second) and then converts it to a number
  4. score = answer/5*100
  5. log("Your answer is " .. str(score) .. "% correct!")
  6. -- score == 100

Back to top 

hexToInt(hex)

Convert a hexadecimal color to its integer equivalent

Parameters

Parameter Type Description
hex Number The hex value, prefixed with "0x"

Return values

Type Description
Number The integer representation

Example(s)

  1. {None currently given}

Back to top 

hexToName(hex, colorScheme)

Converts a color in hexadecimal to the closest matching name

Parameters

Parameter Type Description
hex Number The hexadecimal value, prefixed with "0x"
colorScheme String See this section for your options.

Return values

Type Description
String The closest matching name based on the inputs

Example(s)

  1. {None currently given}

Back to top 

hexToRgb(hex)

Converts a hexadecimal to red, green, blue format

Parameters

Parameter Type Description
hex Number The hex value, prefixed by "0x"

Return values

Type Description
Number The number representation

Example(s)

  1. {None currently given}

Back to top 

intToHex(int)

Converts an integer representation of a color to hexadecimal

Parameters

Parameter Type Description
int Number The integer color you want to be converted

Return values

Type Description
String A string of the hexidecimal value

Example(s)

  1. {None currently given}

Back to top 

intToName(i, colorScheme)

Converts an integer color to its closest name

Parameters

Parameter Type Description
i Number The color in integer format that you want to convert
colorScheme String See this section for your options.

Return values

Type Description
String The closest matching name based on the input

Example(s)

  1. {None currently given}

Back to top 

rgbToHex(r,g,b)

Converts a color in RGB format to its hexadecimal value

Parameters

Parameter Type Description
r, g, b Numbers The red, green, and blue values for the color; Note that I comressed these values into one row for simplicity. When calling the function, these values are separated

Return values

Type Description
String The hexadecimal equivalent

Example(s)

  1. {None currently given}

Back to top 

rgbToName(r, g, b, colorScheme)

Converts a color in red, green, blue format to the closest matching name

Parameters

Parameter Type Description
r, g, b Numbers The red, green, and blue values
colorScheme String See this section for your options.

Return values

Type Description
String The closest matching color name based on the input

Example(s)

  1. {None currently given}


Back to top 

xToName Color Scheme Options

For the xToName functions, the second parameter allows for a "colorScheme". Of the 4 choices for schemes, pick the one which suits your needs the best.

Below, I list a description of all 4 and your options for the "colorScheme" parameter.

Note that, for each of the color schemes, each level builds upon the previous; in addition, colors #1 takes 3 from grayscale, #2 takes 9 from grayscale, and #3 takes the remaining 7 from grayscale.

  1. Grayscale - This scheme includes black and white, along with 19 shades of gray in between. Available options to use this scheme are:
    • 0
    • "gray"
    • "grey"
  2. Colors #1 - This scheme has 20 colors total (3 from previous + 17 new). Available options to use this scheme are:
    • 1
    • "small"
    • "basic"
  3. Colors #2 - This scheme has 59 colors total (20 from previous + 39 new). Available options to use this scheme are:
    • 2
    • "medium"
    • "indepth"
  4. Colors #3 - This scheme has 89 colors total (59 from previous + 30 new). Available options to use this scheme are:
    • 3
    • "large"
    • "complete"