1*8e3e3a7aSWarner Losh /* 2*8e3e3a7aSWarner Losh ** $Id: ldo.h,v 2.29 2015/12/21 13:02:14 roberto Exp $ 3*8e3e3a7aSWarner Losh ** Stack and Call structure of Lua 4*8e3e3a7aSWarner Losh ** See Copyright Notice in lua.h 5*8e3e3a7aSWarner Losh */ 6*8e3e3a7aSWarner Losh 7*8e3e3a7aSWarner Losh #ifndef ldo_h 8*8e3e3a7aSWarner Losh #define ldo_h 9*8e3e3a7aSWarner Losh 10*8e3e3a7aSWarner Losh 11*8e3e3a7aSWarner Losh #include "lobject.h" 12*8e3e3a7aSWarner Losh #include "lstate.h" 13*8e3e3a7aSWarner Losh #include "lzio.h" 14*8e3e3a7aSWarner Losh 15*8e3e3a7aSWarner Losh 16*8e3e3a7aSWarner Losh /* 17*8e3e3a7aSWarner Losh ** Macro to check stack size and grow stack if needed. Parameters 18*8e3e3a7aSWarner Losh ** 'pre'/'pos' allow the macro to preserve a pointer into the 19*8e3e3a7aSWarner Losh ** stack across reallocations, doing the work only when needed. 20*8e3e3a7aSWarner Losh ** 'condmovestack' is used in heavy tests to force a stack reallocation 21*8e3e3a7aSWarner Losh ** at every check. 22*8e3e3a7aSWarner Losh */ 23*8e3e3a7aSWarner Losh #define luaD_checkstackaux(L,n,pre,pos) \ 24*8e3e3a7aSWarner Losh if (L->stack_last - L->top <= (n)) \ 25*8e3e3a7aSWarner Losh { pre; luaD_growstack(L, n); pos; } else { condmovestack(L,pre,pos); } 26*8e3e3a7aSWarner Losh 27*8e3e3a7aSWarner Losh /* In general, 'pre'/'pos' are empty (nothing to save) */ 28*8e3e3a7aSWarner Losh #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 29*8e3e3a7aSWarner Losh 30*8e3e3a7aSWarner Losh 31*8e3e3a7aSWarner Losh 32*8e3e3a7aSWarner Losh #define savestack(L,p) ((char *)(p) - (char *)L->stack) 33*8e3e3a7aSWarner Losh #define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) 34*8e3e3a7aSWarner Losh 35*8e3e3a7aSWarner Losh 36*8e3e3a7aSWarner Losh /* type of protected functions, to be ran by 'runprotected' */ 37*8e3e3a7aSWarner Losh typedef void (*Pfunc) (lua_State *L, void *ud); 38*8e3e3a7aSWarner Losh 39*8e3e3a7aSWarner Losh LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 40*8e3e3a7aSWarner Losh const char *mode); 41*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_hook (lua_State *L, int event, int line); 42*8e3e3a7aSWarner Losh LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); 43*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 44*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 45*8e3e3a7aSWarner Losh LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 46*8e3e3a7aSWarner Losh ptrdiff_t oldtop, ptrdiff_t ef); 47*8e3e3a7aSWarner Losh LUAI_FUNC int luaD_poscall (lua_State *L, CallInfo *ci, StkId firstResult, 48*8e3e3a7aSWarner Losh int nres); 49*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); 50*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_growstack (lua_State *L, int n); 51*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_shrinkstack (lua_State *L); 52*8e3e3a7aSWarner Losh LUAI_FUNC void luaD_inctop (lua_State *L); 53*8e3e3a7aSWarner Losh 54*8e3e3a7aSWarner Losh LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 55*8e3e3a7aSWarner Losh LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 56*8e3e3a7aSWarner Losh 57*8e3e3a7aSWarner Losh #endif 58*8e3e3a7aSWarner Losh 59