ldo.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. ** $Id: ldo.h $
  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, 1); pos; } \
  21. else { condmovestack(L,pre,pos); }
  22. /* In general, 'pre'/'pos' are empty (nothing to save) */
  23. #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
  24. #define savestack(L,p) ((char *)(p) - (char *)L->stack)
  25. #define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
  26. /* macro to check stack size, preserving 'p' */
  27. #define checkstackp(L,n,p) \
  28. luaD_checkstackaux(L, n, \
  29. ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
  30. luaC_checkGC(L), /* stack grow uses memory */ \
  31. p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
  32. /* macro to check stack size and GC */
  33. #define checkstackGC(L,fsize) \
  34. luaD_checkstackaux(L, (fsize), (void)0, luaC_checkGC(L))
  35. /* type of protected functions, to be ran by 'runprotected' */
  36. typedef void (*Pfunc) (lua_State *L, void *ud);
  37. LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
  38. LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
  39. const char *mode);
  40. LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
  41. int fTransfer, int nTransfer);
  42. LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
  43. LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);
  44. LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
  45. LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
  46. LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func);
  47. LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
  48. ptrdiff_t oldtop, ptrdiff_t ef);
  49. LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
  50. LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
  51. LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
  52. LUAI_FUNC void luaD_shrinkstack (lua_State *L);
  53. LUAI_FUNC void luaD_inctop (lua_State *L);
  54. LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
  55. LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
  56. #endif