# lua/ldo.c File Reference

`#include <setjmp.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include "lua.h"`
`#include "ldebug.h"`
`#include "ldo.h"`
`#include "lfunc.h"`
`#include "lgc.h"`
`#include "lmem.h"`
`#include "lobject.h"`
`#include "lopcodes.h"`
`#include "lparser.h"`
`#include "lstate.h"`
`#include "lstring.h"`
`#include "ltable.h"`
`#include "ltm.h"`
`#include "lundump.h"`
`#include "lvm.h"`
`#include "lzio.h"`
Include dependency graph for ldo.c:

Go to the source code of this file.

## Data Structures

struct | lua_longjmp
struct | SParser

## Defines

#define | ldo_c
#define | LUA_CORE
#define | inc_ci(L)

## Functions

void | luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop)
static void | restore_stack_limit (lua_State *L)
static void | resetstack (lua_State *L, int status)
void | luaD_throw (lua_State *L, int errcode)
int | luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud)
static void | correctstack (lua_State *L, TValue *oldstack)
void | luaD_reallocstack (lua_State *L, int newsize)
void | luaD_reallocCI (lua_State *L, int newsize)
void | luaD_growstack (lua_State *L, int n)
static CallInfo * | growCI (lua_State *L)
void | luaD_callhook (lua_State *L, int event, int line)
static StkId | adjust_varargs (lua_State *L, Proto *p, int actual)
static StkId | tryfuncTM (lua_State *L, StkId func)
int | luaD_precall (lua_State *L, StkId func, int nresults)
static StkId | callrethooks (lua_State *L, StkId firstResult)
int | luaD_poscall (lua_State *L, StkId firstResult)
void | luaD_call (lua_State *L, StkId func, int nResults)
static void | resume (lua_State *L, void *ud)
static int | resume_error (lua_State *L, const char *msg)
LUA_API int | lua_resume (lua_State *L, int nargs)
LUA_API int | lua_yield (lua_State *L, int nresults)
int | luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef)
static void | f_parser (lua_State *L, void *ud)
int | luaD_protectedparser (lua_State *L, ZIO *z, const char *name)

## Define Documentation

#define inc_ci | ( | L |  | ) |

Value:

    ((L->ci == L->end_ci) ? growCI(L) : \
       (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci))

Definition at line 259 of file ldo.c.

Referenced by luaD_precall().

#define ldo_c

Definition at line 12 of file ldo.c.

#define LUA_CORE

Definition at line 13 of file ldo.c.

## Function Documentation

static StkId adjust_varargs | ( | lua_State * | L,
|  | Proto * | p,
|  | int | actual |
| ) |  |  | `[static]`

Definition at line 208 of file ldo.c.

References cast_num, Proto::is_vararg, iswhite, lua_assert, luaC_checkGC, luaH_new(), luaH_setnum(), luaH_setstr(), luaS_newliteral, Proto::numparams, obj2gco, sethvalue, setnilvalue, setnvalue, setobj2n, setobjs2s, lua_State::top, VARARG_HASARG, and VARARG_NEEDSARG.

Referenced by luaD_precall().

static StkId callrethooks | ( | lua_State * | L,
|  | StkId | firstResult |
| ) |  |  | `[static]`

Definition at line 331 of file ldo.c.

References lua_State::ci, f_isLua, luaD_callhook(), restorestack, savestack, and CallInfo::tailcalls.

Referenced by luaD_poscall().

static void correctstack | ( | lua_State * | L,
|  | TValue * | oldstack |
| ) |  |  | `[static]`

Definition at line 126 of file ldo.c.

References lua_State::base, CallInfo::base, lua_State::base_ci, CallInfo::func, GCObject::gch, gco2uv, lua_State::openupval, lua_State::stack, CallInfo::top, and lua_State::top.

Referenced by luaD_reallocstack().

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

Definition at line 488 of file ldo.c.

References SParser::buff, cast, gt, hvalue, incr_top, Closure::l, luaC_checkGC, luaF_newLclosure(), luaF_newupval(), luaU_undump(), luaY_parser(), luaZ_lookahead(), SParser::name, Proto::nups, LClosure::p, setclvalue, lua_State::top, LClosure::upvals, and SParser::z.

Referenced by luaD_protectedparser().

static CallInfo* growCI | ( | lua_State * | L | ) | `[static]`

Definition at line 169 of file ldo.c.

References lua_State::ci, luaD_reallocCI(), luaD_throw(), luaG_runerror(), and lua_State::size_ci.

LUA_API int lua_resume | ( | lua_State * | L,
|  | int | nargs |
| ) |  |  |

Definition at line 417 of file ldo.c.

References lua_State::base_ci, cast_byte, lua_State::ci, lua_State::errfunc, lua_assert, lua_lock, lua_unlock, luaD_rawrunprotected(), luaD_seterrorobj(), lua_State::nCcalls, resume(), resume_error(), lua_State::status, lua_longjmp::status, CallInfo::top, and lua_State::top.

LUA_API int lua_yield | ( | lua_State * | L,
|  | int | nresults |
| ) |  |  |

Definition at line 441 of file ldo.c.

References lua_State::base, lua_lock, lua_unlock, luaG_runerror(), lua_State::nCcalls, lua_State::status, and lua_State::top.

void luaD_call | ( | lua_State * | L,
|  | StkId | func,
|  | int | nResults |
| ) |  |  |

Definition at line 369 of file ldo.c.

References luaC_checkGC, luaD_precall(), luaD_throw(), luaG_runerror(), luaV_execute(), lua_State::nCcalls, and PCRLUA.

Referenced by callTM(), callTMres(), f_call(), f_Ccall(), GCTM(), lua_call(), luaG_errormsg(), and luaV_execute().

void luaD_callhook | ( | lua_State * | L,
|  | int | event,
|  | int | line |
| ) |  |  |

Definition at line 181 of file ldo.c.

References lua_State::allowhook, lua_State::base_ci, cast_int, lua_State::ci, lua_State::hook, lua_assert, lua_lock, lua_unlock, luaD_checkstack, restorestack, savestack, lua_State::stack_last, CallInfo::top, and lua_State::top.

Referenced by callrethooks(), luaD_precall(), and traceexec().

void luaD_growstack | ( | lua_State * | L,
|  | int | n |
| ) |  |  |

Definition at line 161 of file ldo.c.

References luaD_reallocstack(), and lua_State::stacksize.

int luaD_pcall | ( | lua_State * | L,
|  | Pfunc | func,
|  | void * | u,
|  | ptrdiff_t | old_top,
|  | ptrdiff_t | ef |
| ) |  |  |

Definition at line 453 of file ldo.c.

References lua_State::allowhook, CallInfo::base, lua_State::base, lua_State::ci, lua_State::errfunc, luaD_rawrunprotected(), luaD_seterrorobj(), luaF_close(), lua_State::nCcalls, restore_stack_limit(), restoreci, restorestack, saveci, CallInfo::savedpc, lua_State::savedpc, and lua_longjmp::status.

Referenced by lua_cpcall(), lua_pcall(), and luaD_protectedparser().

int luaD_poscall | ( | lua_State * | L,
|  | StkId | firstResult |
| ) |  |  |

Definition at line 342 of file ldo.c.

References lua_State::base, callrethooks(), lua_State::ci, CallInfo::func, lua_State::hookmask, CallInfo::nresults, lua_State::savedpc, setnilvalue, setobjs2s, and lua_State::top.

Referenced by luaD_precall(), luaV_execute(), and resume().

int luaD_precall | ( | lua_State * | L,
|  | StkId | func,
|  | int | nresults |
| ) |  |  |

Definition at line 264 of file ldo.c.

References adjust_varargs(), CallInfo::base, lua_State::base, cast_int, lua_State::ci, clvalue, Proto::code, curr_func, CallInfo::func, lua_State::hookmask, inc_ci, Proto::is_vararg, lua_assert, lua_lock, lua_unlock, luaD_callhook(), luaD_checkstack, luaD_poscall(), Proto::maxstacksize, CallInfo::nresults, Proto::numparams, LClosure::p, PCRC, PCRLUA, PCRYIELD, restorestack, lua_State::savedpc, CallInfo::savedpc, savestack, setnilvalue, lua_State::stack_last, CallInfo::tailcalls, CallInfo::top, lua_State::top, tryfuncTM(), and ttisfunction.

Referenced by luaD_call(), luaV_execute(), and resume().

int luaD_protectedparser | ( | lua_State * | L,
|  | ZIO * | z,
|  | const char * | name |
| ) |  |  |

Definition at line 506 of file ldo.c.

References SParser::buff, lua_State::errfunc, f_parser(), luaD_pcall(), luaZ_freebuffer, luaZ_initbuffer, SParser::name, savestack, lua_State::top, and SParser::z.

Referenced by lua_load().

int luaD_rawrunprotected | ( | lua_State * | L,
|  | Pfunc | f,
|  | void * | ud |
| ) |  |  |

Definition at line 111 of file ldo.c.

References lua_State::errorJmp, lua_longjmp::previous, and lua_longjmp::status.

Referenced by lua_close(), lua_newstate(), lua_resume(), and luaD_pcall().

void luaD_reallocCI | ( | lua_State * | L,
|  | int | newsize |
| ) |  |  |

Definition at line 152 of file ldo.c.

References lua_State::base_ci, lua_State::ci, lua_State::end_ci, luaM_reallocvector, and lua_State::size_ci.

Referenced by checkstacksizes(), growCI(), and restore_stack_limit().

void luaD_reallocstack | ( | lua_State * | L,
|  | int | newsize |
| ) |  |  |

Definition at line 141 of file ldo.c.

References correctstack(), EXTRA_STACK, lua_assert, luaM_reallocvector, lua_State::stack, lua_State::stack_last, and lua_State::stacksize.

Referenced by checkstacksizes(), and luaD_growstack().

void luaD_seterrorobj | ( | lua_State * | L,
|  | int | errcode,
|  | StkId | oldtop |
| ) |  |  |

Definition at line 51 of file ldo.c.

References luaS_newliteral, MEMERRMSG, setobjs2s, setsvalue2s, and lua_State::top.

Referenced by lua_resume(), luaD_pcall(), and resetstack().

void luaD_throw | ( | lua_State * | L,
|  | int | errcode |
| ) |  |  |

Definition at line 94 of file ldo.c.

References cast_byte, lua_State::errorJmp, EXIT_FAILURE, G, lua_unlock, resetstack(), lua_State::status, and lua_longjmp::status.

Referenced by error(), growCI(), luaD_call(), luaG_errormsg(), luaM_realloc_(), and luaX_lexerror().

static void resetstack | ( | lua_State * | L,
|  | int | status |
| ) |  |  | `[static]`

Definition at line 81 of file ldo.c.

References lua_State::allowhook, CallInfo::base, lua_State::base, lua_State::base_ci, lua_State::ci, lua_State::errfunc, lua_State::errorJmp, luaD_seterrorobj(), luaF_close(), lua_State::nCcalls, and restore_stack_limit().

Referenced by luaD_throw().

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

Definition at line 71 of file ldo.c.

References lua_State::base_ci, cast_int, lua_State::ci, EXTRA_STACK, lua_assert, luaD_reallocCI(), lua_State::size_ci, lua_State::stack, lua_State::stack_last, and lua_State::stacksize.

Referenced by luaD_pcall(), and resetstack().

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

Definition at line 383 of file ldo.c.

References CallInfo::base, lua_State::base, lua_State::base_ci, cast, cast_int, lua_State::ci, f_isLua, GET_OPCODE, lua_assert, luaD_poscall(), luaD_precall(), luaV_execute(), OP_CALL, OP_TAILCALL, PCRLUA, lua_State::status, CallInfo::top, and lua_State::top.

Referenced by lua_resume().

static int resume_error | ( | lua_State * | L,
|  | const char * | msg |
| ) |  |  | `[static]`

Definition at line 408 of file ldo.c.

References CallInfo::base, lua_State::ci, incr_top, lua_unlock, luaS_new, setsvalue2s, and lua_State::top.

Referenced by lua_resume().

static StkId tryfuncTM | ( | lua_State * | L,
|  | StkId | func |
| ) |  |  | `[static]`

Definition at line 243 of file ldo.c.

References incr_top, luaG_typeerror(), luaT_gettmbyobj(), restorestack, savestack, setobj2s, setobjs2s, TM_CALL, lua_State::top, and ttisfunction.

Referenced by luaD_precall().