lfunc.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. {
  25. TValue *v; /* points to stack or to its own value */
  26. lu_mem refcount; /* reference counter */
  27. union
  28. {
  29. struct /* (when open) */
  30. {
  31. UpVal *next; /* linked list */
  32. int touched; /* mark to avoid cycles with dead threads */
  33. } open;
  34. TValue value; /* the value (when closed) */
  35. } u;
  36. };
  37. #define upisopen(up) ((up)->v != &(up)->u.value)
  38. LUAI_FUNC Proto *luaF_newproto(lua_State *L);
  39. LUAI_FUNC CClosure *luaF_newCclosure(lua_State *L, int nelems);
  40. LUAI_FUNC LClosure *luaF_newLclosure(lua_State *L, int nelems);
  41. LUAI_FUNC void luaF_initupvals(lua_State *L, LClosure *cl);
  42. LUAI_FUNC UpVal *luaF_findupval(lua_State *L, StkId level);
  43. LUAI_FUNC void luaF_close(lua_State *L, StkId level);
  44. LUAI_FUNC void luaF_freeproto(lua_State *L, Proto *f);
  45. LUAI_FUNC const char *luaF_getlocalname(const Proto *func, int local_number,
  46. int pc);
  47. #endif