lfunc.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. ** $Id: lfunc.h,v 2.13 2014/02/18 13:39:37 roberto Exp roberto $
  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, sizeof(CClosure)) + \
  10. cast(int, sizeof(TValue)*((n)-1)))
  11. #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
  12. cast(int, sizeof(TValue *)*((n)-1)))
  13. /* test whether thread is in 'twups' list */
  14. #define isintwups(L) (L->twups != L)
  15. /*
  16. ** Upvalues for Lua closures
  17. */
  18. struct UpVal {
  19. TValue *v; /* points to stack or to its own value */
  20. lu_mem refcount; /* reference counter */
  21. union {
  22. struct { /* (when open) */
  23. UpVal *next; /* linked list */
  24. int touched; /* mark to avoid cycles with dead threads */
  25. } open;
  26. TValue value; /* the value (when closed) */
  27. } u;
  28. };
  29. #define upisopen(up) ((up)->v != &(up)->u.value)
  30. LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  31. LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);
  32. LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);
  33. LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
  34. LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  35. LUAI_FUNC void luaF_close (lua_State *L, StkId level);
  36. LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  37. LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  38. int pc);
  39. #endif