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.

utf8.codepoint()
  • References/Lua/Lua/Standard Libraries/UTF-8 Support

utf8.codepoint (s [, i [, j]])sijiji

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

_VERSION A global variable (not a function) that holds a string containing the running Lua version. The current value of this variable is "Lua 5.3".

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

debug.setupvalue (f, up, value) This function assigns the value value to the upvalue with index up of the function f. The function returns

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

string.rep (s, n [, sep])nssepsepn (Note that it is very easy to exhaust the memory of your machine with a single

2025-01-10 15:47:30
package.cpath
  • References/Lua/Lua/Standard Libraries/Modules

package.cpath The path used by require to search for a C loader. Lua

2025-01-10 15:47:30
Format Strings for Pack and Unpack
  • References/Lua/Lua/Standard Libraries/String Manipulation

6.4.2 – Format Strings for Pack and Unpack The first argument to string.pack

2025-01-10 15:47:30
package.config
  • References/Lua/Lua/Standard Libraries/Modules

package.config A string describing some compile-time configurations for packages. This string is a sequence of lines: The first line is the directory separator string

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

debug.gethook ([thread]) Returns the current hook settings of the thread, as three values: the current hook function, the current hook mask, and the current hook count (as set

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

math.ult (m, n) Returns a boolean, true if and only if integer m is below integer n when they are compared as unsigned integers.

2025-01-10 15:47:30
coroutine.status()
  • References/Lua/Lua/Standard Libraries/Coroutine Manipulation

coroutine.status (co) Returns the status of coroutine co, as a string: "running", if the coroutine is running (that is, it called status);

2025-01-10 15:47:30