Edit on GitHub

Libraries

This is a list of built-in libraries in Nelua.

To use a library use require 'libraryname'.

This page is under construction and very incomplete.

arg

Arg library allows to use command line arguments from the entry point.

Variable Name Description
global arg: sequence(stringview, GeneralAllocator) Sequence of command line arguments.

basic

Basic library contains common functions.

Variable Name Description
global likely(x: boolean): boolean Binding for GNUC __builtin_expect(x, 1).
global unlikely(x: boolean): boolean Binding for GNUC __builtin_expect(x, 0).
global panic(msg: stringview) Returns an error message and stops execution.
global error(msg: stringview) Alias of panic.
global assert(cond: auto, msg: auto) Asserts the condition condand errors if it’s false.
global _VERSION: stringview A string of Nelua version.

iterators

Iterators library contains iterator related functions.

Variable Name Description
ipairs(list: L): (Next, *L, integer) Work with vector, sequence, span and array.
mipairs(list: L): (Next, *L, integer) Like ipairs but yields reference to elements so that you can modify.
pairs(list: L): (Next, *L, K) Currently is an alias to ipairs.
mpairs(list: L): (Next, *L, K) Like mpairs but yields reference to elements so that you can modify.
next(list: L, [index: K]): (boolean, K, T) Works with vector, sequence, span and array.
mnext(list: L, [index: K]): (boolean, K, *T) Like next but returns reference to elements so that you can modify.

filestream

Filestream library contains filestream record, mainly used for io library.

Variable Name Description
global filestream filestream record.
filestream.id: uint64 file id.
filestream.open(filename: stringview[, mode: stringview]): (filestream, stringview, integer) Opens a file with given mode (default is r). Returns empty filesystem, error message and error code if failed.
filestream:flush(): (boolean, stringview, integer) Flushes the file.
filestream:close(): (boolean, stringview, integer) Closes the file.
filestream:seek([whence: stringview[, offset: integer]]): (integer, stringview, integer) Returns the caret position or goes to given offset or returns the size.
filestream:setvbuf(mode: stringview[, size: integer]) Sets buffer size.
filestream:read(fmt: [integer, stringview, niltype]): (string, stringview, integer) Reads the content of the file according to the given format.
filestream:write(s: stringview): (boolean, stringview, integer) Writes text to the file.
filestream:isopen(): boolean Returns open state of the file.
filestream:__tostring(): string converts the handled FILEptr to string.

io

IO library, copies Lua io library.

Variable Name Description
global io io record.
global io.stderr: filestream Error file.
global io.stdout: filestream Output file used for io.write.
global io.stdin: filestream Input file used for io.read.
io.open(filename: stringview[, mode: stringview]) : (filestream, stringview, integer) Opens a file. Alias of filestream.open.
io.flush(file: filestream): boolean Flushes the file
io.close([file]) Alias of file:close. Closes io.stdout if no file was given.
io.input(file: [stringview, filestream, niltype]): filestream Sets, opens or returns the input file.
io.output(file: [stringview, filestream, niltype]): filestream Sets, opens or returns the output file.
io.tmpfile(): (filestream, stringview, integer) Returns a temporary file.
io.read(fmt: [integer, stringview, niltype]): (string, stringview, integer) Alias of io.stdin:read.
io.write(s: stringview): (boolean, stringview, integer) Alias of io.stdout:write.
io.type(x: auto) Returns a type of a file. Returns nil if not a file.
io.isopen(file: filestream): boolean Alias of file:isopen.

math

Math library, copies Lua math library with extra functions.

Variable Name Description
global math math record
global math.pi The compile-time value of #[math.pi]#, which is the the value of π.
global math.huge The compile-time value of #[math.huge]#, which is a value greater than any other numeric value.
global math.maxinteger The maximum possible compile-time value of integer.
global math.mininteger The minimum possible compile-time value of integer.
math.abs(x) Returns the absolute value of x.
math.ceil(x) Returns the smallest integral value greater than or equal to x.
math.floor(x) Returns the largest integral value less than or equal to x.
math.ifloor(x): integer Returns the result of math.floor(x), but returns an integer.
math.sqrt(x) Returns the square root of x.
math.exp(x) Returns the value eˣ (where e is the base of natural logarithms).
math.acos(x) Returns the arc cosine of x (in radians).
math.asin(x) Returns the arc sine of x (in radians).
math.cos(x) Returns the cosine of x (assumed to be in radians).
math.sin(x) Returns the sine of x (assumed to be in radians).
math.tan(x) Returns the tangent of x (assumed to be in radians).
math.cosh(x) Returns the hyperbolic cosine of x.
math.sinh(x) Returns the hyperbolic sine of x.
math.tanh(x) Returns the hyperbolic tangent of x.
math.log10(x) Returns the base-10 logarithm of x.
math.max(x, y) Returns the argument with the maximum value, according to the Nelua operator <.
math.min(x, y) Returns the argument with the minimum value, according to the Nelua operator <.
math.fmod(x, y) Returns the remainder of the division of x by y that rounds the quotient towards zero.
math.atan2(y, x) Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.).
math.pow(x, y) Returns xʸ. (You can also use the expression x^y to compute this value.).
math.atan(y[, x]) If x argument is passed, it returns the same value as math.atan2(y, x), otherwise it returns the arc tangent of y (in radians).
math.log(x[, base]) If base argument is passed, it returns the logarithm of x in the given base, otherwise it returns the natural logarithm of x).
math.deg(x) Converts the angle x from radians to degrees.
math.rad(x) Returns the angle x (given in degrees) in radians.
math.modf(x) Returns the integral part of x and the fractional part of x.
math.frexp(x) Returns m (multiplier) and e (exponent) such that x = m2ᵉ, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero).
math.ldexp(m, e) Returns m2ᵉ (e should be an integral).
math.tointeger(x) If the value x is convertible to an integer, returns that integer. Otherwise, returns nil.
math.type(x) Returns "integer" if x is an integral, "float" if it is a float, or "nil" if x is not a number.
math.ult(m, n) Both m and n should be convertible to an integer; returns true if and only if integer m is below integer n when they are compared as unsigned integers.
math.randomseed(x) Sets x as the “seed” for the pseudo-random generator: equal seeds produce equal sequences of numbers.
math.random([m[, n]]) When called without arguments, returns a pseudo-random float with uniform distribution in the range [0,1). When called with two integers m and n, it returns a pseudo-random integer with uniform distribution in the range [m, n]. The call math.random(n), for a positive n, is equivalent to math.random(1,n).

memory

Memory library description (TODO)

Variable Name Description
memory.copy(dest, src, size)  
memory.move(dest, src, size)  
memory.set(dest, x, size)  
memory.zero(dest, size)  
diff = memory.compare(a, b, size)  
result = memory.equals(a, b, size)  
ptr = memory.scan(p, x, size)  
ptr = memory.find(heystack, heystacksize, needle, needlesize)  
memory.spancopy(dest, src)  
memory.spanmove(dest, src)  
memory.spanset(dest, x)  
memory.spanzero(dest)  
memory.spancompare(a, b)  
result = memory.spanequals(a, b)  
size = memory.spanfind(s, x)  
result = memory.spancontains(s, x)  
newa = memory.moveval(a) Returns a memory copy of the dereference of pointer a leaving its contents zero filled. Deprecated.
memory.swapval(a, b) Swaps memory of the dereference of pointer a and b. Deprecated.

os

OS library description (TODO)

Variable Name Description
clock = os.clock()  
strdate = os.date()  
diff = os.difftime(time1, time2)  
status, errstr, errno = os.execute(command)  
os.exit(code)  
envval = os.getenv(varname)  
result, errstr, errno = os.remove(filename)  
result, errstr, errno = os.rename(filename)  
result = os.setlocale(locale, category)  
os_time_desc  
timestamp = os.time(desc)  
name = os.tmpname()  

resourcepool

Resource Pool library description (TODO)

Variable Name Description
resourcepool Resourcepool constructor.

sequence

Sequence library description (TODO)

Variable Name Description
sequence Sequence constructor.

span

Span library description (TODO)

Variable Name Description
span Span constructor

string

String library description (TODO)

Variable Name Description
string String type.
tostring Converts values to string using __tostring.
string.__tocstring  
string.__tostringview  
string.__convert  
string.sub  
string.rep  
string.reverse  
string.upper  
string.lower  
string.char  
string.format  
string.__concat  
string.__len  
string.__eq  
string.__lt  
string.__le  
string.__add  
string.__sub  
string.__mul  
string.__div  
string.__idiv  
string.__mod  
string.__pow  
string.__unm  
string.__band  
string.__bor  
string.__bxor  
string.__shl  
string.__shr  
string.__bnot  
string.len  
string.byte  
string.find  
string.subview  
stringview.__concat  
stringview.rep  
stringview.sub  
stringview.reverse  
stringview.upper  
stringview.lower  
stringview.format  

stringbuilder

String Builder library description (TODO)

Variable Name Description
stringbuilder.make Stringbuilder constructor.

stringview

String View library description (TODO)

Variable Name Description
tostringview  
tonumber  
tointeger  
stringview.__len  
stringview.__eq  
stringview.__lt  
stringview.__le  
stringview.len  
stringview.byte  
stringview.subview  
stringview.find  
stringview.__add  
stringview.__sub  
stringview.__mul  
stringview.__div  
stringview.__idiv  
stringview.__mod  
stringview.__pow  
stringview.__unm  
stringview.__band  
stringview.__bor  
stringview.__bxor  
stringview.__shl  
stringview.__shr  
stringview.__bnot  

traits

Traits library description (TODO)

Variable Name Description
typeid Typedef of uint32.
valtypeid = typeid_of(val) Returns typeid of the given value.
str = type(val) Returns a type as stringview of the given value.
typeinfo Type info record.
valtypeinfo = typeinfo_of(val) Return typeinfo of the given val.

vector

Vector library, typically used as an efficient vector.

Variable Name Description
vector(T) Generic vector type expression.
vectorT.size: usize Number of elements in the vector.
vectorT.data: span(T) Elements storage of the vector.
vectorT.allocator: Allocator Allocator of the vector.
vectorT.make(allocator) Create a vector using a custom allocator instance.
vectorT:clear() Removes all elements from the vector.
vectorT:destroy() Resets the vector to zeroed state, freeing all used resources.
vectorT:reserve(n: usize) Reserve at least n elements in the vector storage.
vectorT:resize(n: usize) Resizes the vector so that it contains n elements.
vectorT:push(v: T) Adds a element v at the end of the vector.
vectorT:pop(): T Removes the last element in the vector and returns its value.
vectorT:insert(pos: usize, v: T) Inserts element v at position pos in the vector.
vectorT:remove(pos: usize): T Removes element at position pos in the vector and returns its value.
vectorT:remove_value(v: T) Removes the first item from the vector whose value is given.
vectorT:remove_if(pred) Removes all elements from the vector where pred function returns true.
vectorT:capacity(): isize Returns the number of elements the vector can store before triggering a reallocation.
vectorT:__atindex(i: usize): *T Returns reference to element at index pos.
vectorT:__len(): isize Returns the number of elements in the vector.

Differences »