lfunc.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. ** $Id: lfunc.h $
  3. ** Auxiliary functions to manipulate prototypes and closures
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lfunc_h
  7. #define lfunc_h
  8. #include "lobject.h"
  9. #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \
  10. cast_int(sizeof(TValue)) * (n))
  11. #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \
  12. cast_int(sizeof(TValue *)) * (n))
  13. /* test whether thread is in 'twups' list */
  14. #define isintwups(L) (L->twups != L)
  15. /*
  16. ** maximum number of upvalues in a closure (both C and Lua). (Value
  17. ** must fit in a VM register.)
  18. */
  19. #define MAXUPVAL 255
  20. #define upisopen(up) ((up)->v != &(up)->u.value)
  21. #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v))
  22. /*
  23. ** maximum number of misses before giving up the cache of closures
  24. ** in prototypes
  25. */
  26. #define MAXMISS 10
  27. /*
  28. ** Special "status" for 'luaF_close'
  29. */
  30. /* close upvalues without running their closing methods */
  31. #define NOCLOSINGMETH (-1)
  32. /* close upvalues running all closing methods in protected mode */
  33. #define CLOSEPROTECT (-2)
  34. LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  35. LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);
  36. LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
  37. LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
  38. LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  39. LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
  40. LUAI_FUNC int luaF_close (lua_State *L, StkId level, int status);
  41. LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
  42. LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  43. LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  44. int pc);
  45. #endif