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