sUtils

sUtils is a utility api with a large amount of functions for various purposes

assetAsset functions.
cacheCache functions, stores files in a cache for faster access.
numericallyContains(Table, value)Loop through a table, and check if it contains the value specified
keyContains(Table, value)Loop through a table, and check if it contains the value specified
getFile(file, url)Grab a file from the internet and save it in the file path.
isOdd(num)Returns a boolean on if the number is odd or not.
split(inputstr, sep)Split a string by it's separator.
cut(str, len [, pad])Cut or pad a string to length.
splice(str, pos, char [, replace])Splice and insert a character into a string.
countLines(file)Count the number of lines in the file.
getSize(path [, ignoreRom=false])Recursively get the size of a folder.
generateRandom()Generate a random number based on math.
diceRoll(size, modifier, dc)Roll a dice with a specified modifier, and check if it passes the DC.
fread(file)Read the contents of a file.
fwrite(file, Contents)Write contents to a file.
hread(url)hread reads from a url
getTime([offset])Get the current time with an offset from UTC.
getZeroTime([offset])Get the current time in a table of strings prepended with 0 if they're single digit.
confirm()Read user input, compare it to a table of agree phrases.
readNumber()Read user input, return tonumber() of it.
poke(Path)Poke a file, creating it if it doesn't exist.
encfwrite(path, object)Serialize a lua object, and write it to a file.
encfread(Path)encfread reads a file, and unserializes the lua object.
webquire(url)Webquire is a require but for URLs
savequire(url)savequire uses webquire but will also save the file and use that if it's found.
canadianify(text)"Canadianify" a text.
americanify(text [, case=1])"Americanify" a text.
insert(tbl, value)Check if a value is already in a table, if not, insert it.
remove(tbl, value)Remove all values from a table.
shallowCopy(tbl)Shallow copy a table, not recursive so doesn't copy table elements.
deepCopy(tbl)Deep copy a table, recurses to nested tables.
assetSource

Asset functions.

load(path, override)Load an image file.
draw(image, opts [, tOutput])Draw an image produced by load.
drawSkgrp(Table)Draw the given skgrp file.
drawSkimg(skimg [, x [, y [, output]]])drawSkimg takes a skimg table, and draws it at the specified location
drawBlit(blit [, x [, y [, output]]])drawBlit is like drawSkimg, but for a normal blit table.
skimgSkimg asset functions.
load(path, override)Source

Load an image file.

Parameters

  1. path string Path to the file, supported types are ".skimg", ".skgrp", ".blit", ".nfp", and ".nft".
  2. override string Type to load file as, overriding the file type.

Returns

  1. table The image file, to be fed into a drawing routine.
draw(image, opts [, tOutput])Source

Draw an image produced by load.

Parameters

  1. image Image to draw.
  2. opts { format? = string, x? = number, y? = number }

    Options for picture drawing.

    • format: Format to draw image as, if unpassed will try to figure out the image type.
    • x: X position to draw image at. Defaults to 1.
    • y: Y position to draw image at. Defaults to 1.
  3. tOutput? table Terminal to draw to. Has different requirements based on image type. Defaults to term.current()
drawSkgrp(Table)Source
Deprecated

skgrp is not maintained, use load, and draw, or drawSkimg

Draw the given skgrp file.

Parameters

  1. Table table of instructions to draw.
drawSkimg(skimg [, x [, y [, output]]])Source

drawSkimg takes a skimg table, and draws it at the specified location

Parameters

  1. skimg table The skimg image to draw.
  2. x? number X coordinate, defaults to 1.
  3. y? number Y coordinate, defaults to 1.
  4. output? table Output terminal, defaults to term.current()
drawBlit(blit [, x [, y [, output]]])Source

drawBlit is like drawSkimg, but for a normal blit table.concat

Parameters

  1. blit table Blit image to draw.
  2. x? number X coordinate of the image, defaults to 1.
  3. y? number X coordinate of the image, defaults to 1.
  4. output? table Output terminal, defaults to term.current().
skimgSource

Skimg asset functions.

getAttributes(image)Get the attributes of a .skimg file or image table.
generateDefaultSkimg(width, height, creator, locked)Generates a skimg image with the provided width, and height.
getAttributes(image)Source

Get the attributes of a .skimg file or image table.

Parameters

  1. image string | table Path to a file, or a .skimg table.

Returns

  1. table Attributes of the image.
generateDefaultSkimg(width, height, creator, locked)Source

Generates a skimg image with the provided width, and height.

Parameters

  1. width number Width of the image.
  2. height number Height of the image.
  3. creator string Creator of the image.
  4. locked boolean Whether or not the file is locked from editing.
cacheSource

Cache functions, stores files in a cache for faster access. (Read only)

cacheDataCache where the files are stored, it's key/value with cache[path] = contents.
cacheLoad(path)Load a file, checks if it's in the cache, if so, return that, if not, return the file and put it in cache.
reload(path)Reload a file in the cache, overwriting it with the new contents.
cacheDataSource

Cache where the files are stored, it's key/value with cache[path] = contents.

cacheLoad(path)Source

Load a file, checks if it's in the cache, if so, return that, if not, return the file and put it in cache.

Parameters

  1. path string Path to the file.

Returns

  1. string Contents of the file
reload(path)Source

Reload a file in the cache, overwriting it with the new contents.

Parameters

  1. path string Path to the file to reload.

Returns

  1. string The old contents of the file.
numericallyContains(Table, value)Source

Loop through a table, and check if it contains the value specified

Parameters

  1. Table table to loop through.
  2. value any Value to look for in the table.

Returns

  1. boolean True if the table contains the value.
keyContains(Table, value)Source

Loop through a table, and check if it contains the value specified

Parameters

  1. Table table to loop through.
  2. value any Value to look for in the table.

Returns

  1. boolean True if the table contains the value.
getFile(file, url)Source

Grab a file from the internet and save it in the file path.

Parameters

  1. file string Path to the file to save in.
  2. url string URL to get the content from.
isOdd(num)Source

Returns a boolean on if the number is odd or not.

Parameters

  1. num number Number to check the oddness.

Returns

  1. boolean odd True if the number is odd.
split(inputstr, sep)Source

Split a string by it's separator.

Parameters

  1. inputstr string String to split.
  2. sep string Separator to split the string by.

Returns

  1. table Table containing the split string.
cut(str, len [, pad])Source

Cut or pad a string to length.

Parameters

  1. str string String to cut or pad.
  2. len number Length to cut or pad to.
  3. pad? string Padding to extend the string if necessary. Defaults to " ".

Returns

  1. string Cut or padded string.
splice(str, pos, char [, replace])Source

Splice and insert a character into a string.

Parameters

  1. str string String to be spliced.
  2. pos number Where to insert the character.
  3. char string Character to insert.
  4. replace? boolean Replace the character, or just insert a new one. Defaults to false.

Returns

  1. string The spliced string.
countLines(file)Source

Count the number of lines in the file.

Parameters

  1. file string File to count the lines of.

Returns

  1. number lines Amount of lines in the file.
getSize(path [, ignoreRom=false])Source

Recursively get the size of a folder.

Parameters

  1. path string Path to the folder or file.
  2. ignoreRom? boolean = false Whether or not to discard all entries of rom.

Returns

  1. number size Size of the folder or file.
generateRandom()Source

Generate a random number based on math.random(), and the current time.

Returns

  1. number A mostly random number.
diceRoll(size, modifier, dc)Source

Roll a dice with a specified modifier, and check if it passes the DC.

Parameters

  1. size number Number of sides of the dice.
  2. modifier number Bonuses of the roll.
  3. dc number DC to check the roll against.

Returns

  1. boolean If the roll passes the DC.
  2. number The final roll.
fread(file)Source

Read the contents of a file.

Parameters

  1. file string Path to the file.

Returns

  1. string | nil Contents of the file, or nil if the file doesn't exist.
fwrite(file, Contents)Source

Write contents to a file.

Parameters

  1. file string Path to the file.
  2. Contents string to write to the file.
hread(url)Source

hread reads from a url

Parameters

  1. url string URL to read from.

Returns

  1. string | nil Contents of the page, if any.
  2. nil | any Failing response, if any.
getTime([offset])Source

Get the current time with an offset from UTC.

Parameters

  1. offset? number Offset from UTC.

Returns

  1. table Table containing the time.
getZeroTime([offset])Source

Get the current time in a table of strings prepended with 0 if they're single digit.

Parameters

  1. offset? number Offset from UTC.

Returns

  1. table Table containing the time.
confirm()Source

Read user input, compare it to a table of agree phrases.

Returns

  1. boolean Whether or not the user agreed to the prompt.
readNumber()Source

Read user input, return tonumber() of it.

Returns

  1. number Number the user input.
poke(Path)Source

Poke a file, creating it if it doesn't exist.

Parameters

  1. Path string to the file.
encfwrite(path, object)Source

Serialize a lua object, and write it to a file.

Parameters

  1. path string Path to the file.
  2. object Any serializable lua object.
encfread(Path)Source

encfread reads a file, and unserializes the lua object.

Parameters

  1. Path string to file.

Returns

  1. Any lua object from the file.
webquire(url)Source

Webquire is a require but for URLs

Parameters

  1. url string URL to download the module from.

Returns

  1. The loaded module, like what require would return.
savequire(url)Source

savequire uses webquire but will also save the file and use that if it's found.

Parameters

  1. url string URL to download the module from.

Returns

  1. The loaded module, like what require would return.
canadianify(text)Source

"Canadianify" a text.

Parameters

  1. text string Text to candianify.

Returns

  1. string Canadian text.
americanify(text [, case=1])Source

"Americanify" a text.

Parameters

  1. text string Text to americanify.
  2. case? number = 1 Which type of modification to use. 1 = "I'm walkin here!" .. text .. " Forget about it!", 2 = "Oil? " .. text .. " The First Amendment."

Returns

  1. string American text.
insert(tbl, value)Source

Check if a value is already in a table, if not, insert it.

Parameters

  1. tbl table Table to insert to.
  2. value Value to insert.

Returns

  1. table Modified table.
remove(tbl, value)Source

Remove all values from a table.

Parameters

  1. tbl table Table to remove from.
  2. value Value to remove.

Returns

  1. table Modified table.
shallowCopy(tbl)Source

Shallow copy a table, not recursive so doesn't copy table elements.

Parameters

  1. tbl table Table to copy.

Returns

  1. table Copied table.
deepCopy(tbl)Source

Deep copy a table, recurses to nested tables.

Parameters

  1. tbl table Table to copy.

Returns

  1. table Copied table.