sUtils
sUtils is a utility api with a large amount of functions for various purposes
asset | Asset functions. |
---|---|
cache | Cache 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. skimg Skimg asset functions. - load(path, override)Source
Load an image file.
Parameters
- path string Path to the file, supported types are ".skimg", ".skgrp", ".blit", ".nfp", and ".nft".
- override string Type to load file as, overriding the file type.
Returns
- table The image file, to be fed into a drawing routine.
- draw(image, opts [, tOutput])Source
Draw an image produced by load.
Parameters
- image Image to draw.
- 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.
- 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
- 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
- drawBlit(blit [, x [, y [, output]]])Source
drawBlit is like drawSkimg, but for a normal blit table.concat
Parameters
- 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
Returns
- table Attributes of the image.
- generateDefaultSkimg(width, height, creator, locked)Source
Generates a
skimg
image with the provided width, and height.Parameters
- width number Width of the image.
- height number Height of the image.
- creator string Creator of the image.
- locked boolean Whether or not the file is locked from editing.
- cacheSource
Cache functions, stores files in a cache for faster access. (Read only)
cacheData Cache 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
- path string Path to the file.
Returns
- string Contents of the file
- reload(path)Source
Reload a file in the cache, overwriting it with the new contents.
Parameters
- path string Path to the file to reload.
Returns
- string The old contents of the file.
- numericallyContains(Table, value)Source
Loop through a table, and check if it contains the value specified
Parameters
- Table table to loop through.
- value any Value to look for in the table.
Returns
- 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
- Table table to loop through.
- value any Value to look for in the table.
Returns
- 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
- isOdd(num)Source
Returns a boolean on if the number is odd or not.
Parameters
- num number Number to check the oddness.
Returns
- boolean odd True if the number is odd.
- split(inputstr, sep)Source
Split a string by it's separator.
Parameters
Returns
- table Table containing the split string.
- cut(str, len [, pad])Source
Cut or pad a string to length.
Parameters
- str string String to cut or pad.
- len number Length to cut or pad to.
- pad? string Padding to extend the string if necessary. Defaults to " ".
Returns
- string Cut or padded string.
- splice(str, pos, char [, replace])Source
Splice and insert a character into a string.
Parameters
- str string String to be spliced.
- pos number Where to insert the character.
- char string Character to insert.
- replace? boolean Replace the character, or just insert a new one. Defaults to false.
Returns
- string The spliced string.
- countLines(file)Source
Count the number of lines in the file.
Parameters
- file string File to count the lines of.
Returns
- number lines Amount of lines in the file.
- getSize(path [, ignoreRom=false])Source
Recursively get the size of a folder.
Parameters
- path string Path to the folder or file.
- ignoreRom? boolean =
false
Whether or not to discard all entries ofrom
.
Returns
- number size Size of the folder or file.
- generateRandom()Source
Generate a random number based on math.random(), and the current time.
Returns
- 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
- size number Number of sides of the dice.
- modifier number Bonuses of the roll.
- dc number DC to check the roll against.
Returns
- boolean If the roll passes the DC.
- number The final roll.
- fread(file)Source
Read the contents of a file.
Parameters
- file string Path to the file.
Returns
- string | nil Contents of the file, or nil if the file doesn't exist.
- fwrite(file, Contents)Source
Write contents to a file.
Parameters
- hread(url)Source
hread reads from a url
Parameters
- url string URL to read from.
Returns
- string | nil Contents of the page, if any.
- nil | any Failing response, if any.
- getTime([offset])Source
Get the current time with an offset from UTC.
Parameters
- offset? number Offset from UTC.
Returns
- 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
- offset? number Offset from UTC.
Returns
- table Table containing the time.
- confirm()Source
Read user input, compare it to a table of agree phrases.
Returns
- boolean Whether or not the user agreed to the prompt.
- readNumber()Source
Read user input, return
tonumber()
of it.Returns
- number Number the user input.
- poke(Path)Source
Poke a file, creating it if it doesn't exist.
Parameters
- Path string to the file.
- encfwrite(path, object)Source
Serialize a lua object, and write it to a file.
Parameters
- path string Path to the file.
- object Any serializable lua object.
- encfread(Path)Source
encfread reads a file, and unserializes the lua object.
Parameters
- Path string to file.
Returns
- Any lua object from the file.
- webquire(url)Source
Webquire is a
require
but for URLsParameters
- url string URL to download the module from.
Returns
- 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
- url string URL to download the module from.
Returns
- The loaded module, like what
require
would return.
- canadianify(text)Source
"Canadianify" a text.
Parameters
- text string Text to candianify.
Returns
- string Canadian text.
- americanify(text [, case=1])Source
"Americanify" a text.
Parameters
- text string Text to americanify.
- 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
- string American text.
- insert(tbl, value)Source
Check if a value is already in a table, if not, insert it.
Parameters
- tbl table Table to insert to.
- value Value to insert.
Returns
- table Modified table.
- remove(tbl, value)Source
Remove all values from a table.
Parameters
- tbl table Table to remove from.
- value Value to remove.
Returns
- table Modified table.
- shallowCopy(tbl)Source
Shallow copy a table, not recursive so doesn't copy table elements.
Parameters
- tbl table Table to copy.
Returns
- table Copied table.
- deepCopy(tbl)Source
Deep copy a table, recurses to nested tables.
Parameters
- tbl table Table to copy.
Returns
- table Copied table.