xref: /netbsd/external/mit/lua/dist/src/ldo.h (revision 6550d01e)
1 /*	$NetBSD: ldo.h,v 1.1.1.1 2010/10/31 11:16:56 mbalmer Exp $	*/
2 
3 /*
4 ** Id: ldo.h,v 2.7.1.1 2007/12/27 13:02:25 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 #define luaD_checkstack(L,n)	\
19   if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \
20     luaD_growstack(L, n); \
21   else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1));
22 
23 
24 #define incr_top(L) {luaD_checkstack(L,1); L->top++;}
25 
26 #define savestack(L,p)		((char *)(p) - (char *)L->stack)
27 #define restorestack(L,n)	((TValue *)((char *)L->stack + (n)))
28 
29 #define saveci(L,p)		((char *)(p) - (char *)L->base_ci)
30 #define restoreci(L,n)		((CallInfo *)((char *)L->base_ci + (n)))
31 
32 
33 /* results from luaD_precall */
34 #define PCRLUA		0	/* initiated a call to a Lua function */
35 #define PCRC		1	/* did a call to a C function */
36 #define PCRYIELD	2	/* C funtion yielded */
37 
38 
39 /* type of protected functions, to be ran by `runprotected' */
40 typedef void (*Pfunc) (lua_State *L, void *ud);
41 
42 LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name);
43 LUAI_FUNC void luaD_callhook (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 int luaD_pcall (lua_State *L, Pfunc func, void *u,
47                                         ptrdiff_t oldtop, ptrdiff_t ef);
48 LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
49 LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
50 LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
51 LUAI_FUNC void luaD_growstack (lua_State *L, int n);
52 
53 LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
54 LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
55 
56 LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
57 
58 #endif
59 
60