Hymn Script
Home Learn Play Download Source Dark

Standard Library


Standard Library

Hymn comes with a set of standard libraries for typical operations.

glob Wildcard text matching
io Input/output
json Parse and save JSON
math Math operations
os Operating system interface
path File path handling
pattern Text pattern matching
text String manipulation

glob

glob(pattern, text) Returns true or false if the pattern matches text. Accepts * and ? special symbols.

io

io.size(path) Returns a file's size in bytes.
io.read(path) Reads a file's contents into a string.
io.read-lines(path) Reads a file's contents into an array of strings, separated by lines.
io.write(path, value) Writes a string into a file, truncating if it exists.
io.append(path, value) Appends a string into a file.
io.exists(path) Returns true or false if a file exists.
io.stats(path) Returns a table of information for a file.
io.input() Reads user input into a string.
io.move(source, destination) Renames a source file path to a destination file path. Returns true or false whether the operation was a success.
io.copy(source, destination) Copies the contents of a source file to a new destination file. Returns true if the operation was a success.
io.remove(path) Removes a file. Returns true or false whether the operation was a success.

json

json.save(value) Converts a hymn value to a JSON string.
json.parse(string) Converts a JSON string to a hymn value.

math

PI Not a tasty pie.
math.abs(number) Returns the absolute value.
math.min(number, number) Returns the smaller of the given two numbers.
math.max(number, number) Returns the larger of the given two numbers.
math.floor(number) Returns the number rounded down.
math.ceil(number) Returns the number rounded up.
math.sin(number) Sine.
math.cos(number) Cosine.
math.tan(number) Tangent.
math.asin(number) Arc sine.
math.acos(number) Arc cosine.
math.sinh(number) Hyperbolic sine.
math.cosh(number) Hyperbolic cosine.
math.atan(number) Arc tangent.
math.atan2(number, number) Arc tangent of Y and X.
math.sqrt(number) Square root.
math.pow(number, number) Base and power.
math.log(number) Natural logarithm.
math.log2(number) Base 2 logarithm.
math.log10(number) Base 10 logarithm.

os

stdout Convencience variable for use with print statements. Equal to 0.
stderr Convencience variable for use with print statements. Equal to 1.
system(string) Runs a system command and returns the resulting output text.
os.clock() Returns a float of the system clock divided by CLOCKS_PER_SEC.
os.env(string) Returns a system environment variable, or none.
os.popen(string, string) Calls popen with file and mode. Returns a pointer.
os.pclose(pointer) Closes a popen pointer.
os.fopen(string, string) Calls fopen with path and mode. Returns a pointer.
os.fclose(pointer) Closes a fopen pointer.
os.fget(pointer) Calls fgetc until EOF is reached on a given pointer. Returns the resulting string.
os.exec(string) Runs a system command and returns the resulting integer code.

path

path.working() Returns the current working directory as a string.
path.convert(path) Converts non-system path separator characters to the current system path separator.
path.normalize(path) Normalizes a path, removing extraneous dots.
path.parent(path) Returns the parent directory of a given path.
path.cat(paths...) Concatenates multiple paths into a single path using the current system path character.
path.absolute(path) Converts a relative path into an absolute path.
path.list(path) Returns an array of files and directories for a given path.
path.walk(path) Recursively descends into a path and returns an array of all files and directories.
path.base(path) Returns the base file name of the path.
path.extension(path) Returns the extension name of a file.
path.symbol() Returns the current system path separator character as a string.

pattern

pattern.get(string, pattern, start) Returns an array of strings or none. The first string is the whole matching substring. Additional strings are for any groups.
pattern.find(string, pattern, start) Returns an array of integers or none if no match is found. The first two integers are the start and end positions of the matching string. Each additional two integers are for groups.
pattern.match(string, pattern, start) Returns true or false whether the whole string matches the pattern.
pattern.replace(string, pattern, replace) Replaces all instances of pattern in string with the replacement string, and returns the updated string.

text

text.contains(string, contains) Returns true or false if string contains the given string.
text.starts(string, starts) Returns true or false if string starts with the given string.
text.ends(string, ends) Returns true or false if string ends with the given string.
text.replace(string, find, replace) Replaces all instances of find in string with the replacement string, and returns the updated string.
text.trim(string) Removes leading and trailing space characters from the string.
text.left-strip(string) Removes leading space characters from the string.
text.right-strip(string) Removes trailing space characters from the string.
text.join(array, string) Converts an array to a string, with an optional string delimiter.
text.split(string, string) Converts a string to an array, using a string delimiter.

Back to Built-ins Learn Primitives