ldo.h 2.3 KB

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