lfunc.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. ** $Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp $
  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. ** 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. /*
  21. ** Upvalues for Lua closures
  22. */
  23. struct UpVal {
  24. TValue *v; /* points to stack or to its own value */
  25. lu_mem refcount; /* reference counter */
  26. union {
  27. struct { /* (when open) */
  28. UpVal *next; /* linked list */
  29. int touched; /* mark to avoid cycles with dead threads */
  30. } open;
  31. TValue value; /* the value (when closed) */
  32. } u;
  33. };
  34. #define upisopen(up) ((up)->v != &(up)->u.value)
  35. LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  36. LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);
  37. LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);
  38. LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
  39. LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  40. LUAI_FUNC void luaF_close (lua_State *L, StkId level);
  41. LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  42. LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  43. int pc);
  44. #endif