Useful Utilities for Lua!
This file was made firstly for myself, but then I wanted to share it with people, so here it is!
string.random(count,min,max)
"count, min, max" are not required, this function returns a random stringstring.split(str,split)
this function splits a string to a tablestring.mix(str)
seemix
string.startswith(str,pattern)
verify if a string starts with the patternstring.endswith(str,pattern)
same as above but for the end of the stringstring.encode
table for encodingstring.decode
table for decodingstring.encode.hex(str)
encode a string into hexstring.decode.hex(str)
decode a string into hexstring.encode.b64(str)
encode a string into base64string.decode.b64(str)
decode a string into base64string.totable
transforms a string to a table
io.readfile(path/to/file.txt)
reads a fileio.store(file,content,true)
stores data into a file, the "true" mean we do a new line at the end of the file for future storing
math.mix
seemix
math.calc
Calculator sandboxed (You can't inject code)
os.find("file","dir")
search for a file in a directoryos.clear()
clear the terminal, works with all OSos.getOS()
returns the current OSos.getArch()
get if the arch is 64 bits or 32 bitsos.outputexec
Get the output of a system commandos.splitpath(path)
Splits the path
table.merge(t1,t2)
merges two tablestable.to2D(str)
returns a 2D table version of the string you senttable.tostring(tbl)
returns a string of the table you senttable.list(tbl)
return in a string a list of elements of a table, also returns counttable.head(tbl)
returns first valuetable.tail(tbl)
returns the tail of the tabletable.find(tbl)
find a value in a tabletable.reverse(tbl)
reverses a table. Warning: only works with normal keys (1,2,3..)
console.log(str)
logs something with time and dateconsole.slowPrint(str)
prints something slowlyconsole.slowWrite(str)
writes something slowly (using io.write)console.error(error type, error message, additional infos)
advanced erroringconsole.update(bool,str...)
Will update the console, bool: is the text slowly appearing.
sleep(t)
will wait the amount of time givenoperator
Operators, can always be usefulmorse
A table with char for morse in itchars
a string with all chars, used forstring.encode.b64(str)
mix
mix a string or intsdostring
a remake of the old loadstring for Lua 5.3 - execute a string as a piece of codeisType
Shorter for type(obj) == "obj"