lapi.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. ** $Id: lapi.h $
  3. ** Auxiliary functions from Lua API
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lapi_h
  7. #define lapi_h
  8. #include "llimits.h"
  9. #include "lstate.h"
  10. #if defined(LUA_USE_APICHECK)
  11. #include <assert.h>
  12. #define api_check(l,e,msg) assert(e)
  13. #else /* for testing */
  14. #define api_check(l,e,msg) ((void)(l), lua_assert((e) && msg))
  15. #endif
  16. /* Increments 'L->top.p', checking for stack overflows */
  17. #define api_incr_top(L) \
  18. (L->top.p++, api_check(L, L->top.p <= L->ci->top.p, "stack overflow"))
  19. /*
  20. ** macros that are executed whenever program enters the Lua core
  21. ** ('lua_lock') and leaves the core ('lua_unlock')
  22. */
  23. #if !defined(lua_lock)
  24. #define lua_lock(L) ((void) 0)
  25. #define lua_unlock(L) ((void) 0)
  26. #endif
  27. /*
  28. ** If a call returns too many multiple returns, the callee may not have
  29. ** stack space to accommodate all results. In this case, this macro
  30. ** increases its stack space ('L->ci->top.p').
  31. */
  32. #define adjustresults(L,nres) \
  33. { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
  34. L->ci->top.p = L->top.p; }
  35. /* Ensure the stack has at least 'n' elements */
  36. #define api_checknelems(L,n) \
  37. api_check(L, (n) < (L->top.p - L->ci->func.p), \
  38. "not enough elements in the stack")
  39. /* Ensure the stack has at least 'n' elements to be popped. (Some
  40. ** functions only update a slot after checking it for popping, but that
  41. ** is only an optimization for a pop followed by a push.)
  42. */
  43. #define api_checkpop(L,n) \
  44. api_check(L, (n) < L->top.p - L->ci->func.p && \
  45. L->tbclist.p < L->top.p - (n), \
  46. "not enough free elements in the stack")
  47. #endif