51 KiB
LuaLS
_G
A global variable (not a function) that holds the global environment (see §2.2). Lua itself does not use this variable; changing its value does not affect any environment, nor vice versa.
_G
_VERSION
A global variable (not a function) that holds a string containing the running Lua version.
string
arg
Command-line arguments of Lua Standalone.
string[]
assert
Raises an error if the value of its argument v is false (i.e., nil
or false
); otherwise, returns all its arguments. In case of error, message
is the error object; when absent, it defaults to "assertion failed!"
function assert(v?: <T>, message?: any, ...any)
-> <T>
2. ...any
collectgarbage
This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt
.
opt:
-> "collect" -- Performs a full garbage-collection cycle.
| "stop" -- Stops automatic execution.
| "restart" -- Restarts automatic execution.
| "count" -- Returns the total memory in Kbytes.
| "step" -- Performs a garbage-collection step.
| "isrunning" -- Returns whether the collector is running.
| "incremental" -- Change the collector mode to incremental.
| "generational" -- Change the collector mode to generational.
function collectgarbage(opt?: "collect"|"count"|"generational"|"incremental"|"isrunning"...(+3), ...any)
-> any
coroutine
coroutinelib
coroutine.close
Closes coroutine co
, closing all its pending to-be-closed variables and putting the coroutine in a dead state.
function coroutine.close(co: thread)
-> noerror: boolean
2. errorobject: any
coroutine.create
Creates a new coroutine, with body f
. f
must be a function. Returns this new coroutine, an object with type "thread"
.
function coroutine.create(f: fun(...any):...unknown)
-> thread
coroutine.isyieldable
Returns true when the coroutine co
can yield. The default for co
is the running coroutine.
function coroutine.isyieldable(co?: thread)
-> boolean
coroutine.resume
Starts or continues the execution of coroutine co
.
function coroutine.resume(co: thread, val1?: any, ...any)
-> success: boolean
2. ...any
coroutine.running
Returns the running coroutine plus a boolean, true when the running coroutine is the main one.
function coroutine.running()
-> running: thread
2. ismain: boolean
coroutine.status
Returns the status of coroutine co
.
return #1:
| "running" -- Is running.
| "suspended" -- Is suspended or not started.
| "normal" -- Is active but not running.
| "dead" -- Has finished or stopped with an error.
function coroutine.status(co: thread)
-> "dead"|"normal"|"running"|"suspended"
coroutine.wrap
Creates a new coroutine, with body f
; f
must be a function. Returns a function that resumes the coroutine each time it is called.
function coroutine.wrap(f: fun(...any):...unknown)
-> fun(...any):...unknown
coroutine.yield
Suspends the execution of the calling coroutine.
(async) function coroutine.yield(...any)
-> ...any
debug
debuglib
debug.debug
Enters an interactive mode with the user, running each string that the user enters.
function debug.debug()
debug.getfenv
Returns the environment of object o
.
function debug.getfenv(o: any)
-> table
debug.gethook
Returns the current hook settings of the thread.
function debug.gethook(co?: thread)
-> hook: function
2. mask: string
3. count: integer
debug.getinfo
Returns a table with information about a function.
what:
+> "n" -- `name` and `namewhat`
+> "S" -- `source`, `short_src`, `linedefined`, `lastlinedefined`, and `what`
+> "l" -- `currentline`
+> "t" -- `istailcall`
+> "u" -- `nups`, `nparams`, and `isvararg`
+> "f" -- `func`
+> "r" -- `ftransfer` and `ntransfer`
+> "L" -- `activelines`
function debug.getinfo(thread: thread, f: integer|fun(...any):...unknown, what?: string|"L"|"S"|"f"|"l"...(+4))
-> debuginfo
debug.getlocal
Returns the name and the value of the local variable with index local
of the function at level f
of the stack.
function debug.getlocal(thread: thread, f: integer|fun(...any):...unknown, index: integer)
-> name: string
2. value: any
debug.getmetatable
Returns the metatable of the given value.
function debug.getmetatable(object: any)
-> metatable: table
debug.getregistry
Returns the registry table.
function debug.getregistry()
-> table
debug.getupvalue
Returns the name and the value of the upvalue with index up
of the function.
function debug.getupvalue(f: fun(...any):...unknown, up: integer)
-> name: string
2. value: any
debug.getuservalue
Returns the n
-th user value associated
to the userdata u
plus a boolean,
false
if the userdata does not have that value.
function debug.getuservalue(u: userdata, n?: integer)
-> any
2. boolean
debug.setcstacklimit
Deprecated in Lua 5.4.2
Sets a new limit for the C stack. This limit controls how deeply nested calls can go in Lua, with the intent of avoiding a stack overflow.
In case of success, this function returns the old limit. In case of error, it returns false
.
function debug.setcstacklimit(limit: integer)
-> boolean|integer
debug.setfenv
Sets the environment of the given object
to the given table
.
function debug.setfenv(object: <T>, env: table)
-> object: <T>
debug.sethook
Sets the given function as a hook.
mask:
+> "c" -- Calls hook when Lua calls a function.
+> "r" -- Calls hook when Lua returns from a function.
+> "l" -- Calls hook when Lua enters a new line of code.
function debug.sethook(thread: thread, hook: fun(...any):...unknown, mask: string|"c"|"l"|"r", count?: integer)
debug.setlocal
Assigns the value
to the local variable with index local
of the function at level
of the stack.
function debug.setlocal(thread: thread, level: integer, index: integer, value: any)
-> name: string
debug.setmetatable
Sets the metatable for the given value to the given table (which can be nil
).
function debug.setmetatable(value: <T>, meta?: table)
-> value: <T>
debug.setupvalue
Assigns the value
to the upvalue with index up
of the function.
function debug.setupvalue(f: fun(...any):...unknown, up: integer, value: any)
-> name: string
debug.setuservalue
Sets the given value
as
the n
-th user value associated to the given udata
.
udata
must be a full userdata.
function debug.setuservalue(udata: userdata, value: any, n?: integer)
-> udata: userdata
debug.traceback
Returns a string with a traceback of the call stack. The optional message string is appended at the beginning of the traceback.
function debug.traceback(thread: thread, message?: any, level?: integer)
-> message: string
debug.upvalueid
Returns a unique identifier (as a light userdata) for the upvalue numbered n
from the given function.
function debug.upvalueid(f: fun(...any):...unknown, n: integer)
-> id: lightuserdata
debug.upvaluejoin
Make the n1
-th upvalue of the Lua closure f1
refer to the n2
-th upvalue of the Lua closure f2
.
function debug.upvaluejoin(f1: fun(...any):...unknown, n1: integer, f2: fun(...any):...unknown, n2: integer)
dofile
Opens the named file and executes its content as a Lua chunk. When called without arguments, dofile
executes the content of the standard input (stdin
). Returns all values returned by the chunk. In case of errors, dofile
propagates the error to its caller. (That is, dofile
does not run in protected mode.)
function dofile(filename?: string)
-> ...any
error
Terminates the last protected function called and returns message as the error object.
Usually, error
adds some information about the error position at the beginning of the message, if the message is a string.
function error(message: any, level?: integer)
getfenv
Returns the current environment in use by the function. f
can be a Lua function or a number that specifies the function at that stack level.
function getfenv(f?: integer|fun(...any):...unknown)
-> table
getmetatable
If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns the associated value. Otherwise, returns the metatable of the given object.
function getmetatable(object: any)
-> metatable: table
io
iolib
io.close
Close file
or default output file.
exitcode:
| "exit"
| "signal"
function io.close(file?: file*)
-> suc: boolean?
2. exitcode: ("exit"|"signal")?
3. code: integer?
io.flush
Saves any written data to default output file.
function io.flush()
io.input
Sets file
as the default input file.
function io.input(file: string|file*)
io.lines
for c in io.lines(filename, ...) do
body
end
...(param):
| "n" -- Reads a numeral and returns it as number.
| "a" -- Reads the whole file.
-> "l" -- Reads the next line skipping the end of line.
| "L" -- Reads the next line keeping the end of line.
function io.lines(filename?: string, ...string|integer|"L"|"a"|"l"...(+1))
-> fun():any, ...unknown
io.open
Opens a file, in the mode specified in the string mode
.
mode:
-> "r" -- Read mode.
| "w" -- Write mode.
| "a" -- Append mode.
| "r+" -- Update mode, all previous data is preserved.
| "w+" -- Update mode, all previous data is erased.
| "a+" -- Append update mode, previous data is preserved, writing is only allowed at the end of file.
| "rb" -- Read mode. (in binary mode.)
| "wb" -- Write mode. (in binary mode.)
| "ab" -- Append mode. (in binary mode.)
| "r+b" -- Update mode, all previous data is preserved. (in binary mode.)
| "w+b" -- Update mode, all previous data is erased. (in binary mode.)
| "a+b" -- Append update mode, previous data is preserved, writing is only allowed at the end of file. (in binary mode.)
function io.open(filename: string, mode?: "a"|"a+"|"a+b"|"ab"|"r"...(+7))
-> file*?
2. errmsg: string?
io.output
Sets file
as the default output file.
function io.output(file: string|file*)
io.popen
Starts program prog in a separated process.
mode:
| "r" -- Read data from this program by `file`.
| "w" -- Write data to this program by `file`.
function io.popen(prog: string, mode?: "r"|"w")
-> file*?
2. errmsg: string?
io.read
Reads the file
, according to the given formats, which specify what to read.
...(param):
| "n" -- Reads a numeral and returns it as number.
| "a" -- Reads the whole file.
-> "l" -- Reads the next line skipping the end of line.
| "L" -- Reads the next line keeping the end of line.
function io.read(...string|integer|"L"|"a"|"l"...(+1))
-> any
2. ...any
io.tmpfile
In case of success, returns a handle for a temporary file.
function io.tmpfile()
-> file*
io.type
Checks whether obj
is a valid file handle.
return #1:
| "file" -- Is an open file handle.
| "closed file" -- Is a closed file handle.
| `nil` -- Is not a file handle.
function io.type(file: file*)
-> "closed file"|"file"|`nil`
io.write
Writes the value of each of its arguments to default output file.
function io.write(...any)
-> file*
2. errmsg: string?
ipairs
Returns three values (an iterator function, the table t
, and 0
) so that the construction
for i,v in ipairs(t) do body end
will iterate over the key–value pairs (1,t[1]), (2,t[2]), ...
, up to the first absent index.
function ipairs(t: <T:table>)
-> fun(table: <V>[], i?: integer):integer, <V>
2. <T:table>
3. i: integer
load
Loads a chunk.
If chunk
is a string, the chunk is this string. If chunk
is a function, load
calls it repeatedly to get the chunk pieces. Each call to chunk
must return a string that concatenates with previous results. A return of an empty string, nil
, or no value signals the end of the chunk.
mode:
| "b" -- Only binary chunks.
| "t" -- Only text chunks.
-> "bt" -- Both binary and text.
function load(chunk: string|function, chunkname?: string, mode?: "b"|"bt"|"t", env?: table)
-> function?
2. error_message: string?
loadfile
Loads a chunk from file filename
or from the standard input, if no file name is given.
mode:
| "b" -- Only binary chunks.
| "t" -- Only text chunks.
-> "bt" -- Both binary and text.
function loadfile(filename?: string, mode?: "b"|"bt"|"t", env?: table)
-> function?
2. error_message: string?
loadstring
Loads a chunk from the given string.
function loadstring(text: string, chunkname?: string)
-> function?
2. error_message: string?
math
mathlib
math.abs
Returns the absolute value of x
.
function math.abs(x: <Number:number>)
-> <Number:number>
math.acos
Returns the arc cosine of x
(in radians).
function math.acos(x: number)
-> number
math.asin
Returns the arc sine of x
(in radians).
function math.asin(x: number)
-> number
math.atan
Returns the arc tangent of y/x
(in radians).
function math.atan(y: number, x?: number)
-> number
math.atan2
Returns the arc tangent of y/x
(in radians).
function math.atan2(y: number, x: number)
-> number
math.ceil
Returns the smallest integral value larger than or equal to x
.
function math.ceil(x: number)
-> integer
math.cos
Returns the cosine of x
(assumed to be in radians).
function math.cos(x: number)
-> number
math.cosh
Returns the hyperbolic cosine of x
(assumed to be in radians).
function math.cosh(x: number)
-> number
math.deg
Converts the angle x
from radians to degrees.
function math.deg(x: number)
-> number
math.exp
Returns the value e^x
(where e
is the base of natural logarithms).
function math.exp(x: number)
-> number
math.floor
Returns the largest integral value smaller than or equal to x
.
function math.floor(x: number)
-> integer
math.fmod
Returns the remainder of the division of x
by y
that rounds the quotient towards zero.
function math.fmod(x: number, y: number)
-> number
math.frexp
Decompose x
into tails and exponents. Returns m
and e
such that x = m * (2 ^ e)
, e
is an integer and the absolute value of m
is in the range [0.5, 1) (or zero when x
is zero).
function math.frexp(x: number)
-> m: number
2. e: number
math.ldexp
Returns m * (2 ^ e)
.
function math.ldexp(m: number, e: number)
-> number
math.log
Returns the logarithm of x
in the given base.
function math.log(x: number, base?: integer)
-> number
math.log10
Returns the base-10 logarithm of x.
function math.log10(x: number)
-> number
math.max
Returns the argument with the maximum value, according to the Lua operator <
.
function math.max(x: <Number:number>, ...<Number:number>)
-> <Number:number>
math.min
Returns the argument with the minimum value, according to the Lua operator <
.
function math.min(x: <Number:number>, ...<Number:number>)
-> <Number:number>
math.modf
Returns the integral part of x
and the fractional part of x
.
function math.modf(x: number)
-> integer
2. number
math.pow
Returns x ^ y
.
function math.pow(x: number, y: number)
-> number
math.rad
Converts the angle x
from degrees to radians.
function math.rad(x: number)
-> number
math.random
math.random()
: Returns a float in the range [0,1).math.random(n)
: Returns a integer in the range [1, n].math.random(m, n)
: Returns a integer in the range [m, n].
function math.random(m: integer, n: integer)
-> integer
math.randomseed
math.randomseed(x, y)
: Concatenatex
andy
into a 128-bitseed
to reinitialize the pseudo-random generator.math.randomseed(x)
: Equate tomath.randomseed(x, 0)
.math.randomseed()
: Generates a seed with a weak attempt for randomness.
function math.randomseed(x?: integer, y?: integer)
math.sin
Returns the sine of x
(assumed to be in radians).
function math.sin(x: number)
-> number
math.sinh
Returns the hyperbolic sine of x
(assumed to be in radians).
function math.sinh(x: number)
-> number
math.sqrt
Returns the square root of x
.
function math.sqrt(x: number)
-> number
math.tan
Returns the tangent of x
(assumed to be in radians).
function math.tan(x: number)
-> number
math.tanh
Returns the hyperbolic tangent of x
(assumed to be in radians).
function math.tanh(x: number)
-> number
math.tointeger
Miss locale <math.tointeger>
function math.tointeger(x: any)
-> integer?
math.type
Miss locale <math.type>
return #1:
| "integer"
| "float"
| 'nil'
function math.type(x: any)
-> "float"|"integer"|'nil'
math.ult
Miss locale <math.ult>
function math.ult(m: integer, n: integer)
-> boolean
module
Creates a module.
function module(name: string, ...any)
newproxy
function newproxy(proxy: boolean|table|userdata)
-> userdata
next
Allows a program to traverse all fields of a table. Its first argument is a table and its second argument is an index in this table. A call to next
returns the next index of the table and its associated value. When called with nil
as its second argument, next
returns an initial index and its associated value. When called with the last index, or with nil
in an empty table, next
returns nil
. If the second argument is absent, then it is interpreted as nil
. In particular, you can use next(t)
to check whether a table is empty.
The order in which the indices are enumerated is not specified, even for numeric indices. (To traverse a table in numerical order, use a numerical for
.)
The behavior of next
is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may set existing fields to nil.
function next(table: table<<K>, <V>>, index?: <K>)
-> <K>?
2. <V>?
os
oslib
os.clock
Returns an approximation of the amount in seconds of CPU time used by the program.
function os.clock()
-> number
os.date
Returns a string or a table containing date and time, formatted according to the given string format
.
function os.date(format?: string, time?: integer)
-> string|osdate
os.difftime
Returns the difference, in seconds, from time t1
to time t2
.
function os.difftime(t2: integer, t1: integer)
-> integer
os.execute
Passes command
to be executed by an operating system shell.
exitcode:
| "exit"
| "signal"
function os.execute(command?: string)
-> suc: boolean?
2. exitcode: ("exit"|"signal")?
3. code: integer?
os.exit
Calls the ISO C function exit
to terminate the host program.
function os.exit(code?: boolean|integer, close?: boolean)
os.getenv
Returns the value of the process environment variable varname
.
function os.getenv(varname: string)
-> string?
os.remove
Deletes the file with the given name.
function os.remove(filename: string)
-> suc: boolean
2. errmsg: string?
os.rename
Renames the file or directory named oldname
to newname
.
function os.rename(oldname: string, newname: string)
-> suc: boolean
2. errmsg: string?
os.setlocale
Sets the current locale of the program.
category:
-> "all"
| "collate"
| "ctype"
| "monetary"
| "numeric"
| "time"
function os.setlocale(locale: string|nil, category?: "all"|"collate"|"ctype"|"monetary"|"numeric"...(+1))
-> localecategory: string
os.time
Returns the current time when called without arguments, or a time representing the local date and time specified by the given table.
function os.time(date?: osdateparam)
-> integer
os.tmpname
Returns a string with a file name that can be used for a temporary file.
function os.tmpname()
-> string
package
packagelib
package.config
A string describing some compile-time configurations for packages.
string
package.loaders
A table used by require
to control how to load modules.
table
package.loadlib
Dynamically links the host program with the C library libname
.
function package.loadlib(libname: string, funcname: string)
-> any
package.searchers
A table used by require
to control how to load modules.
table
package.searchpath
Searches for the given name
in the given path
.
function package.searchpath(name: string, path: string, sep?: string, rep?: string)
-> filename: string?
2. errmsg: string?
package.seeall
Sets a metatable for module
with its __index
field referring to the global environment, so that this module inherits values from the global environment. To be used as an option to function module
.
function package.seeall(module: table)
pairs
If t
has a metamethod __pairs
, calls it with t as argument and returns the first three results from the call.
Otherwise, returns three values: the next function, the table t
, and nil
, so that the construction
for k,v in pairs(t) do body end
will iterate over all key–value pairs of table t
.
See function next for the caveats of modifying the table during its traversal.
function pairs(t: <T:table>)
-> fun(table: table<<K>, <V>>, index?: <K>):<K>, <V>
2. <T:table>
pcall
Calls the function f
with the given arguments in protected mode. This means that any error inside f
is not propagated; instead, pcall
catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall
also returns all results from the call, after this first result. In case of any error, pcall
returns false
plus the error object.
function pcall(f: fun(...any):...unknown, arg1?: any, ...any)
-> success: boolean
2. result: any
3. ...any
Receives any number of arguments and prints their values to stdout
, converting each argument to a string following the same rules of tostring.
The function print is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use string.format and io.write.
function print(...any)
rawequal
Checks whether v1 is equal to v2, without invoking the __eq
metamethod.
function rawequal(v1: any, v2: any)
-> boolean
rawget
Gets the real value of table[index]
, without invoking the __index
metamethod.
function rawget(table: table, index: any)
-> any
rawlen
Returns the length of the object v
, without invoking the __len
metamethod.
function rawlen(v: string|table)
-> len: integer
rawset
Sets the real value of table[index]
to value
, without using the __newindex
metavalue. table
must be a table, index
any value different from nil
and NaN
, and value
any Lua value.
This function returns table
.
function rawset(table: table, index: any, value: any)
-> table
require
Loads the given module, returns any value returned by the searcher(true
when nil
). Besides that value, also returns as a second result the loader data returned by the searcher, which indicates how require
found the module. (For instance, if the module came from a file, this loader data is the file path.)
function require(modname: string)
-> unknown
2. loaderdata: unknown
select
If index
is a number, returns all arguments after argument number index
; a negative number indexes from the end (-1
is the last argument). Otherwise, index
must be the string "#"
, and select
returns the total number of extra arguments it received.
index:
| "#"
function select(index: integer|"#", ...any)
-> any
setfenv
Sets the environment to be used by the given function.
function setfenv(f: fun(...any):...integer|unknown, table: table)
-> function
setmetatable
Sets the metatable for the given table. If metatable
is nil
, removes the metatable of the given table. If the original metatable has a __metatable
field, raises an error.
This function returns table
.
To change the metatable of other types from Lua code, you must use the debug library (§6.10).
function setmetatable(table: table, metatable?: table|metatable)
-> table
string
stringlib
string.byte
Returns the internal numeric codes of the characters s[i], s[i+1], ..., s[j]
.
function string.byte(s: string|number, i?: integer, j?: integer)
-> ...integer
string.char
Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.
function string.char(byte: integer, ...integer)
-> string
string.dump
Returns a string containing a binary representation (a binary chunk) of the given function.
function string.dump(f: fun(...any):...unknown, strip?: boolean)
-> string
string.find
Looks for the first match of pattern
(see §6.4.1) in the string.
@return start
@return end
@return ...
— captured
function string.find(s: string|number, pattern: string|number, init?: integer, plain?: boolean)
-> start: integer|nil
2. end: integer|nil
3. ...any
string.format
Returns a formatted version of its variable number of arguments following the description given in its first argument.
function string.format(s: string|number, ...any)
-> string
string.gmatch
Returns an iterator function that, each time it is called, returns the next captures from pattern
(see §6.4.1) over the string s.
As an example, the following loop will iterate over all the words from string s, printing one per line:
s =
"hello world from Lua"
for w in string.gmatch(s, "%a+") do
print(w)
end
function string.gmatch(s: string|number, pattern: string|number, init?: integer)
-> fun():string, ...unknown
string.gsub
Returns a copy of s in which all (or the first n
, if given) occurrences of the pattern
(see §6.4.1) have been replaced by a replacement string specified by repl
.
function string.gsub(s: string|number, pattern: string|number, repl: string|number|function|table, n?: integer)
-> string
2. count: integer
string.len
Returns its length.
function string.len(s: string|number)
-> integer
string.lower
Returns a copy of this string with all uppercase letters changed to lowercase.
function string.lower(s: string|number)
-> string
string.match
Looks for the first match of pattern
(see §6.4.1) in the string.
function string.match(s: string|number, pattern: string|number, init?: integer)
-> ...any
string.pack
Returns a binary string containing the values v1
, v2
, etc. packed (that is, serialized in binary form) according to the format string fmt
(see §6.4.2) .
function string.pack(fmt: string, v1: string|number, v2?: string|number, ...string|number)
-> binary: string
string.packsize
Returns the size of a string resulting from string.pack
with the given format string fmt
(see §6.4.2) .
function string.packsize(fmt: string)
-> integer
string.rep
Returns a string that is the concatenation of n
copies of the string s
separated by the string sep
.
function string.rep(s: string|number, n: integer, sep?: string|number)
-> string
string.reverse
Returns a string that is the string s
reversed.
function string.reverse(s: string|number)
-> string
string.sub
Returns the substring of the string that starts at i
and continues until j
.
function string.sub(s: string|number, i: integer, j?: integer)
-> string
string.unpack
Returns the values packed in string according to the format string fmt
(see §6.4.2) .
function string.unpack(fmt: string, s: string, pos?: integer)
-> ...any
2. offset: integer
string.upper
Returns a copy of this string with all lowercase letters changed to uppercase.
function string.upper(s: string|number)
-> string
table
tablelib
table.concat
Given a list where all elements are strings or numbers, returns the string list[i]..sep..list[i+1] ··· sep..list[j]
.
function table.concat(list: table, sep?: string, i?: integer, j?: integer)
-> string
table.foreach
Executes the given f over all elements of table. For each element, f is called with the index and respective value as arguments. If f returns a non-nil value, then the loop is broken, and this value is returned as the final value of foreach.
function table.foreach(list: any, callback: fun(key: string, value: any):<T>|nil)
-> <T>|nil
table.foreachi
Executes the given f over the numerical indices of table. For each index, f is called with the index and respective value as arguments. Indices are visited in sequential order, from 1 to n, where n is the size of the table. If f returns a non-nil value, then the loop is broken and this value is returned as the result of foreachi.
function table.foreachi(list: any, callback: fun(key: string, value: any):<T>|nil)
-> <T>|nil
table.getn
Returns the number of elements in the table. This function is equivalent to #list
.
function table.getn(list: <T>[])
-> integer
table.insert
Inserts element value
at position pos
in list
.
function table.insert(list: table, pos: integer, value: any)
table.maxn
Returns the largest positive numerical index of the given table, or zero if the table has no positive numerical indices.
function table.maxn(table: table)
-> integer
table.move
Moves elements from table a1
to table a2
.
a2[t],··· =
a1[f],···,a1[e]
return a2
function table.move(a1: table, f: integer, e: integer, t: integer, a2?: table)
-> a2: table
table.pack
Returns a new table with all arguments stored into keys 1
, 2
, etc. and with a field "n"
with the total number of arguments.
function table.pack(...any)
-> table
table.remove
Removes from list
the element at position pos
, returning the value of the removed element.
function table.remove(list: table, pos?: integer)
-> any
table.sort
Sorts list elements in a given order, in-place, from list[1]
to list[#list]
.
function table.sort(list: <T>[], comp?: fun(a: <T>, b: <T>):boolean)
table.unpack
Returns the elements from the given list. This function is equivalent to
return list[i], list[i+1], ···, list[j]
By default, i
is 1
and j
is #list
.
function table.unpack(list: <T>[], i?: integer, j?: integer)
-> ...<T>
tonumber
When called with no base
, tonumber
tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber
returns this number; otherwise, it returns fail
.
The conversion of strings can result in integers or floats, according to the lexical conventions of Lua (see §3.1). The string may have leading and trailing spaces and a sign.
function tonumber(e: any)
-> number?
tostring
Receives a value of any type and converts it to a string in a human-readable format.
If the metatable of v
has a __tostring
field, then tostring
calls the corresponding value with v
as argument, and uses the result of the call as its result. Otherwise, if the metatable of v
has a __name
field with a string value, tostring
may use that string in its final result.
For complete control of how numbers are converted, use string.format.
function tostring(v: any)
-> string
type
Returns the type of its only argument, coded as a string. The possible results of this function are "nil"
(a string, not the value nil
), "number"
, "string"
, "boolean"
, "table"
, "function"
, "thread"
, and "userdata"
.
type:
| "nil"
| "number"
| "string"
| "boolean"
| "table"
| "function"
| "thread"
| "userdata"
function type(v: any)
-> type: "boolean"|"function"|"nil"|"number"|"string"...(+3)
uname
machine
string
release
string
sysname
string
version
string
unamelib
numid
function unamelib.numid(x: integer)
-> integer
plusone
function unamelib.plusone(x: integer)
-> integer
uname
function unamelib.uname()
-> uname
unpack
Returns the elements from the given list
. This function is equivalent to
return list[i], list[i+1], ···, list[j]
function unpack(list: <T>[], i?: integer, j?: integer)
-> ...<T>
function unpack(list: { [1]: <T1>, [2]: <T2>, [3]: <T3>, [4]: <T4>, [5]: <T5>, [6]: <T6>, [7]: <T7>, [8]: <T8>, [9]: <T9> })
-> <T1>
2. <T2>
3. <T3>
4. <T4>
5. <T5>
6. <T6>
7. <T7>
8. <T8>
9. <T9>
utf8
utf8lib
utf8.char
Receives zero or more integers, converts each one to its corresponding UTF-8 byte sequence and returns a string with the concatenation of all these sequences.
function utf8.char(code: integer, ...integer)
-> string
utf8.codepoint
Returns the codepoints (as integers) from all characters in s
that start between byte position i
and j
(both included).
function utf8.codepoint(s: string, i?: integer, j?: integer, lax?: boolean)
-> code: integer
2. ...integer
utf8.codes
Returns values so that the construction
for p, c in utf8.codes(s) do
body
end
will iterate over all UTF-8 characters in string s, with p being the position (in bytes) and c the code point of each character. It raises an error if it meets any invalid byte sequence.
function utf8.codes(s: string, lax?: boolean)
-> fun(s: string, p: integer):integer, integer
utf8.len
Returns the number of UTF-8 characters in string s
that start between positions i
and j
(both inclusive).
function utf8.len(s: string, i?: integer, j?: integer, lax?: boolean)
-> integer?
2. errpos: integer?
utf8.offset
Returns the position (in bytes) where the encoding of the n
-th character of s
(counting from position i
) starts.
function utf8.offset(s: string, n: integer, i?: integer)
-> p: integer
warn
Emits a warning with a message composed by the concatenation of all its arguments (which should be strings).
function warn(message: string, ...any)
xpcall
Calls function f
with the given arguments in protected mode with a new message handler.
function xpcall(f: fun(...any):...unknown, msgh: function, arg1?: any, ...any)
-> success: boolean
2. result: any
3. ...any