6 – Standard Libraries

The standard Lua libraries provide useful functions that are implemented directly through the C API. Some of these functions provide essential services to the language (e.g., type and getmetatable); others provide access to "outside" services (e.g., I/O); and others could be implemented in Lua itself, but are quite useful or have critical performance requirements that deserve an implementation in C (e.g., table.sort).

All libraries are implemented through the official C API and are provided as separate C modules. Currently, Lua has the following standard libraries:

  • basic library (§6.1);
  • coroutine library (§6.2);
  • package library (§6.3);
  • string manipulation (§6.4);
  • basic UTF-8 support (§6.5);
  • table manipulation (§6.6);
  • mathematical functions (§6.7) (sin, log, etc.);
  • input and output (§6.8);
  • operating system facilities (§6.9);
  • debug facilities (§6.10).

Except for the basic and the package libraries, each library provides all its functions as fields of a global table or as methods of its objects.

To have access to these libraries, the C host program should call the luaL_openlibs function, which opens all standard libraries. Alternatively, the host program can open them individually by using luaL_requiref to call luaopen_base (for the basic library), luaopen_package (for the package library), luaopen_coroutine (for the coroutine library), luaopen_string (for the string library), luaopen_utf8 (for the UTF8 library), luaopen_table (for the table library), luaopen_math (for the mathematical library), luaopen_io (for the I/O library), luaopen_os (for the operating system library), and luaopen_debug (for the debug library). These functions are declared in lualib.h.

table.move()
  • References/Lua/Lua/Standard Libraries/Table Manipulation

table.move (a1, f, e, t [,a2]) Moves elements from table a1 to table a2, performing the equivalent to the following multiple assignment: a2[t]

2025-01-10 15:47:30
math.acos()
  • References/Lua/Lua/Standard Libraries/Mathematical Functions

math.acos (x) Returns the arc cosine of x (in radians).

2025-01-10 15:47:30
math.sin()
  • References/Lua/Lua/Standard Libraries/Mathematical Functions

math.sin (x) Returns the sine of x (assumed to be in radians).

2025-01-10 15:47:30
math.cos()
  • References/Lua/Lua/Standard Libraries/Mathematical Functions

math.cos (x) Returns the cosine of x (assumed to be in radians).

2025-01-10 15:47:30
debug.upvalueid()
  • References/Lua/Lua/Standard Libraries/The Debug Library

debug.upvalueid (f, n) Returns a unique identifier (as a light userdata) for the upvalue numbered n from the given function. These unique identifiers allow

2025-01-10 15:47:30
string.find()
  • References/Lua/Lua/Standard Libraries/String Manipulation

string.find (s, pattern [, init [, plain]]) Looks for the first match of pattern (see

2025-01-10 15:47:30
table.insert()
  • References/Lua/Lua/Standard Libraries/Table Manipulation

table.insert (list, [pos,] value) Inserts element value at position pos in list, shifting up the elements list[pos], list[pos+1],

2025-01-10 15:47:30
collectgarbage()
  • References/Lua/Lua/Standard Libraries/Basic Functions

collectgarbage ([opt [, arg]]) This function is a generic interface to the garbage collector. It performs different functions according to its first argument, opt:

2025-01-10 15:47:30
pairs()
  • References/Lua/Lua/Standard Libraries/Basic Functions

pairs (t) If t has a metamethod __pairs, calls it with t as argument and returns the first three results from the call. Otherwise

2025-01-10 15:47:30
math.huge
  • References/Lua/Lua/Standard Libraries/Mathematical Functions

math.huge The float value HUGE_VAL, a value larger than any other numeric value.

2025-01-10 15:47:30