# lua/lstate.c File Reference

`#include <stddef.h>`
`#include "lua.h"`
`#include "ldebug.h"`
`#include "ldo.h"`
`#include "lfunc.h"`
`#include "lgc.h"`
`#include "llex.h"`
`#include "lmem.h"`
`#include "lstate.h"`
`#include "lstring.h"`
`#include "ltable.h"`
`#include "ltm.h"`
Include dependency graph for lstate.c:

Go to the source code of this file.

## Data Structures

struct | LG

## Defines

#define | lstate_c
#define | LUA_CORE
#define | state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
#define | fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
#define | tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))

## Typedefs

typedef struct LG | LG

## Functions

static void | stack_init (lua_State *L1, lua_State *L)
static void | freestack (lua_State *L, lua_State *L1)
static void | f_luaopen (lua_State *L, void *ud)
static void | preinit_state (lua_State *L, global_State *g)
static void | close_state (lua_State *L)
lua_State * | luaE_newthread (lua_State *L)
void | luaE_freethread (lua_State *L, lua_State *L1)
LUA_API lua_State * | lua_newstate (lua_Alloc f, void *ud)
static void | callallgcTM (lua_State *L, void *ud)
LUA_API void | lua_close (lua_State *L)

## Define Documentation

#define fromstate | ( | l |  | ) | (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)

Definition at line 28 of file lstate.c.

Referenced by close_state(), and luaE_freethread().

#define lstate_c

Definition at line 10 of file lstate.c.

#define LUA_CORE

Definition at line 11 of file lstate.c.

#define state_size | ( | x |  | ) | (sizeof(x) + LUAI_EXTRASPACE)

Definition at line 27 of file lstate.c.

Referenced by close_state(), lua_newstate(), luaE_freethread(), and luaE_newthread().

#define tostate | ( | l |  | ) | (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))

Definition at line 29 of file lstate.c.

Referenced by lua_newstate(), and luaE_newthread().

## Typedef Documentation

typedef struct LG LG

## Function Documentation

static void callallgcTM | ( | lua_State * | L,
|  | void * | ud |
| ) |  |  | `[static]`

Definition at line 193 of file lstate.c.

References luaC_callGCTM(), and UNUSED.

Referenced by lua_close().

static void close_state | ( | lua_State * | L | ) | `[static]`

Definition at line 105 of file lstate.c.

References global_State::buff, global_State::frealloc, freestack(), fromstate, G, lua_assert, luaC_freeall(), luaF_close(), luaM_freearray, luaZ_freebuffer, stringtable::nuse, obj2gco, global_State::rootgc, lua_State::stack, state_size, global_State::strt, global_State::totalbytes, and global_State::ud.

Referenced by lua_close(), and lua_newstate().

static void f_luaopen | ( | lua_State * | L,
|  | void * | ud |
| ) |  |  | `[static]`

Definition at line 70 of file lstate.c.

References G, global_State::GCthreshold, gt, luaH_new(), luaS_fix, luaS_newliteral, luaS_resize(), luaT_init(), luaX_init(), MEMERRMSG, registry, sethvalue, stack_init(), global_State::totalbytes, and UNUSED.

Referenced by lua_newstate().

static void freestack | ( | lua_State * | L,
|  | lua_State * | L1 |
| ) |  |  | `[static]`

Definition at line 61 of file lstate.c.

References lua_State::base_ci, luaM_freearray, lua_State::size_ci, lua_State::stack, and lua_State::stacksize.

Referenced by close_state(), and luaE_freethread().

LUA_API void lua_close | ( | lua_State * | L | ) |

Definition at line 199 of file lstate.c.

References CallInfo::base, lua_State::base, lua_State::base_ci, callallgcTM(), lua_State::ci, close_state(), lua_State::errfunc, G, lua_assert, lua_lock, luaC_separateudata(), luaD_rawrunprotected(), luaF_close(), lua_State::nCcalls, lua_State::stack, and lua_State::top.

LUA_API lua_State* lua_newstate | ( | lua_Alloc | f,
|  | void * | ud |
| ) |  |  |

Definition at line 143 of file lstate.c.

References bit2mask, global_State::buff, close_state(), global_State::currentwhite, f_luaopen(), FIXEDBIT, global_State::frealloc, global_State::gcdept, global_State::gcpause, GCSpause, global_State::gcstate, global_State::gcstepmul, global_State::GCthreshold, global_State::gray, global_State::grayagain, stringtable::hash, UpVal::l, luaC_white, luaD_rawrunprotected(), luaZ_initbuffer, global_State::mainthread, global_State::mt, NUM_TAGS, stringtable::nuse, obj2gco, global_State::panic, preinit_state(), registry, global_State::rootgc, set2bits, setnilvalue, SFIXEDBIT, stringtable::size, state_size, global_State::strt, global_State::sweepgc, global_State::sweepstrgc, global_State::tmudata, tostate, global_State::totalbytes, UpVal::u, global_State::ud, global_State::uvhead, global_State::weak, and WHITE0BIT.

void luaE_freethread | ( | lua_State * | L,
|  | lua_State * | L1 |
| ) |  |  |

Definition at line 134 of file lstate.c.

References freestack(), fromstate, lua_assert, luaF_close(), luaM_freemem, lua_State::openupval, lua_State::stack, and state_size.

Referenced by freeobj().

lua_State* luaE_newthread | ( | lua_State * | L | ) |

Definition at line 119 of file lstate.c.

References lua_State::basehookcount, G, gt, lua_State::hook, lua_State::hookmask, iswhite, lua_assert, luaC_link(), luaM_malloc, obj2gco, preinit_state(), resethookcount, setobj2n, stack_init(), state_size, and tostate.

Referenced by lua_newthread().

static void preinit_state | ( | lua_State * | L,
|  | global_State * | g |
| ) |  |  | `[static]`

Definition at line 84 of file lstate.c.

References lua_State::allowhook, lua_State::base_ci, lua_State::basehookcount, lua_State::ci, lua_State::errfunc, lua_State::errorJmp, G, gt, lua_State::hook, lua_State::hookmask, lua_State::nCcalls, lua_State::openupval, resethookcount, lua_State::savedpc, setnilvalue, lua_State::size_ci, lua_State::stack, lua_State::stacksize, and lua_State::status.

Referenced by lua_newstate(), and luaE_newthread().

static void stack_init | ( | lua_State * | L1,
|  | lua_State * | L |
| ) |  |  | `[static]`

Definition at line 42 of file lstate.c.

References CallInfo::base, lua_State::base, lua_State::base_ci, BASIC_CI_SIZE, BASIC_STACK_SIZE, lua_State::ci, lua_State::end_ci, EXTRA_STACK, CallInfo::func, luaM_newvector, setnilvalue, lua_State::size_ci, lua_State::stack, lua_State::stack_last, lua_State::stacksize, CallInfo::top, and lua_State::top.

Referenced by f_luaopen(), and luaE_newthread().