lapi.h 1.3 KB

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