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.

debug.traceback()
  • References/Lua/Lua/Standard Libraries/The Debug Library

debug.traceback ([thread,] [message [, level]]) If message is present but is neither a string nor nil, this function returns message without further

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

string.dump (function [, strip]) Returns a string containing a binary representation (a binary chunk) of the given function, so that a later

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

coroutine.wrap (f) Creates a new coroutine, with body f. f must be a function. Returns a function that resumes the coroutine each time it is called.

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

print (···)stdouttostringprint

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
rawget()
  • References/Lua/Lua/Standard Libraries/Basic Functions

rawget (table, index)table[index]__indextableindex

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

getmetatable (object) If object does not have a metatable, returns nil. Otherwise, if the object's metatable has a __metatable field, returns

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

debug.upvaluejoin (f1, n1, f2, n2) Make the n1-th upvalue of the Lua closure f1 refer to the n2-th upvalue of the Lua closure f2

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

package.searchpath (name, path [, sep [, rep]]) Searches for the given name in the given path. A path is a string containing a sequence of templates

2025-01-10 15:47:30
os.setlocale()
  • References/Lua/Lua/Standard Libraries/Operating System Facilities

os.setlocale (locale [, category]) Sets the current locale of the program. locale is a system-dependent string specifying a locale; category is an optional

2025-01-10 15:47:30