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 skgrpfile.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
stringPath to the file, supported types are ".skimg", ".skgrp", ".blit", ".nfp", and ".nft". - override
stringType to load file as, overriding the file type.
Returns
tableThe image file, to be fed into a drawing routine.
- path
- 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?
tableTerminal to draw to. Has different requirements based on image type. Defaults toterm.current()
- drawSkgrp(Table)Source
Deprecated
skgrp is not maintained, use
load, anddraw, ordrawSkimgDraw the given
skgrpfile.Parameters
- Table
tableof instructions to draw.
- Table
- 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 .skimgfile or image table.generateDefaultSkimg(width, height, creator, locked) Generates a skimgimage with the provided width, and height.- getAttributes(image)Source
Get the attributes of a
.skimgfile or image table.Parameters
Returns
tableAttributes of the image.
- generateDefaultSkimg(width, height, creator, locked)Source
Generates a
skimgimage with the provided width, and height.Parameters
- width
numberWidth of the image. - height
numberHeight of the image. - creator
stringCreator of the image. - locked
booleanWhether or not the file is locked from editing.
- width
- 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
stringPath to the file.
Returns
stringContents of the file
- path
- reload(path)Source
Reload a file in the cache, overwriting it with the new contents.
Parameters
- path
stringPath to the file to reload.
Returns
stringThe old contents of the file.
- path
- numericallyContains(Table, value)Source
Loop through a table, and check if it contains the value specified
Parameters
- Table
tableto loop through. - value
anyValue to look for in the table.
Returns
booleanTrue if the table contains the value.
- Table
- keyContains(Table, value)Source
Loop through a table, and check if it contains the value specified
Parameters
- Table
tableto loop through. - value
anyValue to look for in the table.
Returns
booleanTrue if the table contains the value.
- Table
- 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
numberNumber to check the oddness.
Returns
booleanodd True if the number is odd.
- num
- split(inputstr, sep)Source
Split a string by it's separator.
Parameters
Returns
tableTable containing the split string.
- cut(str, len [, pad])Source
Cut or pad a string to length.
Parameters
- str
stringString to cut or pad. - len
numberLength to cut or pad to. - pad?
stringPadding to extend the string if necessary. Defaults to " ".
Returns
stringCut or padded string.
- str
- splice(str, pos, char [, replace])Source
Splice and insert a character into a string.
Parameters
- str
stringString to be spliced. - pos
numberWhere to insert the character. - char
stringCharacter to insert. - replace?
booleanReplace the character, or just insert a new one. Defaults to false.
Returns
stringThe spliced string.
- str
- countLines(file)Source
Count the number of lines in the file.
Parameters
- file
stringFile to count the lines of.
Returns
numberlines Amount of lines in the file.
- file
- getSize(path [, ignoreRom=false])Source
Recursively get the size of a folder.
Parameters
- path
stringPath to the folder or file. - ignoreRom?
boolean=falseWhether or not to discard all entries ofrom.
Returns
numbersize Size of the folder or file.
- path
- generateRandom()Source
Generate a random number based on math.random(), and the current time.
Returns
numberA mostly random number.
- diceRoll(size, modifier, dc)Source
Roll a dice with a specified modifier, and check if it passes the DC.
Parameters
- size
numberNumber of sides of the dice. - modifier
numberBonuses of the roll. - dc
numberDC to check the roll against.
Returns
booleanIf the roll passes the DC.numberThe final roll.
- size
- fread(file)Source
Read the contents of a file.
Parameters
- file
stringPath to the file.
Returns
string| nil Contents of the file, or nil if the file doesn't exist.
- file
- fwrite(file, Contents)Source
Write contents to a file.
Parameters
- hread(url)Source
hread reads from a url
Parameters
- url
stringURL to read from.
Returns
string| nil Contents of the page, if any.- nil |
anyFailing response, if any.
- url
- getTime([offset])Source
Get the current time with an offset from UTC.
Parameters
- offset?
numberOffset from UTC.
Returns
tableTable containing the time.
- offset?
- getZeroTime([offset])Source
Get the current time in a table of strings prepended with
0if they're single digit.Parameters
- offset?
numberOffset from UTC.
Returns
tableTable containing the time.
- offset?
- confirm()Source
Read user input, compare it to a table of agree phrases.
Returns
booleanWhether or not the user agreed to the prompt.
- readNumber()Source
Read user input, return
tonumber()of it.Returns
numberNumber the user input.
- poke(Path)Source
Poke a file, creating it if it doesn't exist.
Parameters
- Path
stringto the file.
- Path
- encfwrite(path, object)Source
Serialize a lua object, and write it to a file.
Parameters
- path
stringPath to the file. - object Any serializable lua object.
- path
- encfread(Path)Source
encfread reads a file, and unserializes the lua object.
Parameters
- Path
stringto file.
Returns
- Any lua object from the file.
- Path
- webquire(url)Source
Webquire is a
requirebut for URLsParameters
- url
stringURL to download the module from.
Returns
- The loaded module, like what
requirewould return.
- url
- savequire(url)Source
savequire uses webquire but will also save the file and use that if it's found.
Parameters
- url
stringURL to download the module from.
Returns
- The loaded module, like what
requirewould return.
- url
- canadianify(text)Source
"Canadianify" a text.
Parameters
- text
stringText to candianify.
Returns
stringCanadian text.
- text
- americanify(text [, case=1])Source
"Americanify" a text.
Parameters
- text
stringText to americanify. - case?
number=1Which type of modification to use. 1 = "I'm walkin here!" .. text .. " Forget about it!", 2 = "Oil? " .. text .. " The First Amendment."
Returns
stringAmerican text.
- text
- insert(tbl, value)Source
Check if a value is already in a table, if not, insert it.
Parameters
- tbl
tableTable to insert to. - value Value to insert.
Returns
tableModified table.
- tbl
- remove(tbl, value)Source
Remove all values from a table.
Parameters
- tbl
tableTable to remove from. - value Value to remove.
Returns
tableModified table.
- tbl
- shallowCopy(tbl)Source
Shallow copy a table, not recursive so doesn't copy table elements.
Parameters
- tbl
tableTable to copy.
Returns
tableCopied table.
- tbl
- deepCopy(tbl)Source
Deep copy a table, recurses to nested tables.
Parameters
- tbl
tableTable to copy.
Returns
tableCopied table.
- tbl