lapi.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /* Increments 'L->top.p', checking for stack overflows */
  11. #define api_incr_top(L) {L->top.p++; \
  12. api_check(L, L->top.p <= L->ci->top.p, \
  13. "stack overflow");}
  14. /*
  15. ** If a call returns too many multiple returns, the callee may not have
  16. ** stack space to accommodate all results. In this case, this macro
  17. ** increases its stack space ('L->ci->top.p').
  18. */
  19. #define adjustresults(L,nres) \
  20. { if ((nres) <= LUA_MULTRET && L->ci->top.p < L->top.p) \
  21. L->ci->top.p = L->top.p; }
  22. /* Ensure the stack has at least 'n' elements */
  23. #define api_checknelems(L,n) \
  24. api_check(L, (n) < (L->top.p - L->ci->func.p), \
  25. "not enough elements in the stack")
  26. /*
  27. ** To reduce the overhead of returning from C functions, the presence of
  28. ** to-be-closed variables in these functions is coded in the CallInfo's
  29. ** field 'nresults', in a way that functions with no to-be-closed variables
  30. ** with zero, one, or "all" wanted results have no overhead. Functions
  31. ** with other number of wanted results, as well as functions with
  32. ** variables to be closed, have an extra check.
  33. */
  34. #define hastocloseCfunc(n) ((n) < LUA_MULTRET)
  35. /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */
  36. #define codeNresults(n) (-(n) - 3)
  37. #define decodeNresults(n) (-(n) - 3)
  38. #endif