4 – The Application Program Interface

This section describes the C API for Lua, that is, the set of C functions available to the host program to communicate with Lua. All API functions and related types and constants are declared in the header file lua.h.

Even when we use the term "function", any facility in the API may be provided as a macro instead. Except where stated otherwise, all such macros use each of their arguments exactly once (except for the first argument, which is always a Lua state), and so do not generate any hidden side-effects.

As in most C libraries, the Lua API functions do not check their arguments for validity or consistency. However, you can change this behavior by compiling Lua with the macro LUA_USE_APICHECK defined.

The Lua library is fully reentrant: it has no global variables. It keeps all information it needs in a dynamic structure, called the Lua state.

Each Lua state has one or more threads, which correspond to independent, cooperative lines of execution. The type lua_State (despite its name) refers to a thread. (Indirectly, through the thread, it also refers to the Lua state associated to the thread.)

A pointer to a thread must be passed as the first argument to every function in the library, except to lua_newstate, which creates a Lua state from scratch and returns a pointer to the main thread in the new state.

lua_isfunction
  • References/Lua/Lua/API/Functions and Types

lua_isfunction[-0, +0, –] int lua_isfunction (lua_State *L, int index); Returns 1 if the value at the given

2025-01-10 15:47:30
lua_Number
  • References/Lua/Lua/API/Functions and Types

lua_Number typedef ... lua_Number; The type of floats in Lua. By default this type is double, but that can be changed to

2025-01-10 15:47:30
lua_geti
  • References/Lua/Lua/API/Functions and Types

lua_geti[-0, +1, e] int lua_geti (lua_State *L, int index, lua_Integer i); Pushes onto the stack

2025-01-10 15:47:30
lua_getupvalue
  • References/Lua/Lua/API/The Debug Interface

lua_getupvalue[-0, +(0|1), –] const char *lua_getupvalue (lua_State *L, int funcindex, int n); Gets information

2025-01-10 15:47:30
lua_pcallk
  • References/Lua/Lua/API/Functions and Types

lua_pcallk[-(nargs + 1), +(nresults|1), –] int lua_pcallk (lua_State *L, int nargs,

2025-01-10 15:47:30
lua_KContext
  • References/Lua/Lua/API/Functions and Types

lua_KContext typedef ... lua_KContext; The type for continuation-function contexts. It must be a numeric type. This type is defined

2025-01-10 15:47:30
lua_xmove
  • References/Lua/Lua/API/Functions and Types

lua_xmove[-?, +?, –] void lua_xmove (lua_State *from, lua_State *to, int n); Exchange values between different

2025-01-10 15:47:30
lua_rawgeti
  • References/Lua/Lua/API/Functions and Types

lua_rawgeti[-0, +1, –] int lua_rawgeti (lua_State *L, int index, lua_Integer n); Pushes onto the stack

2025-01-10 15:47:30
lua_isnoneornil
  • References/Lua/Lua/API/Functions and Types

lua_isnoneornil[-0, +0, –] int lua_isnoneornil (lua_State *L, int index); Returns 1 if the given index

2025-01-10 15:47:30
lua_iscfunction
  • References/Lua/Lua/API/Functions and Types

lua_iscfunction[-0, +0, –] int lua_iscfunction (lua_State *L, int index); Returns 1 if the value at the

2025-01-10 15:47:30