lfunc.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.p != &(up)->u.value)
  21. #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v.p))
  22. /*
  23. ** maximum number of misses before giving up the cache of closures
  24. ** in prototypes
  25. */
  26. #define MAXMISS 10
  27. /* special status to close upvalues preserving the top of the stack */
  28. #define CLOSEKTOP (-1)
  29. LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  30. LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);
  31. LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
  32. LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
  33. LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  34. LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
  35. LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
  36. LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
  37. LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
  38. LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  39. LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  40. int pc);
  41. LUAI_FUNC void luaF_shareproto (Proto *func);
  42. #endif