lfunc.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. ** $Id: lfunc.h,v 2.10 2013/08/27 18:53:35 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. /*
  14. ** Upvalues for Lua closures
  15. */
  16. struct UpVal {
  17. TValue *v; /* points to stack or to its own value */
  18. lu_mem refcount; /* reference counter */
  19. union {
  20. struct { /* (when open) */
  21. UpVal *next; /* linked list */
  22. int touched; /* mark to avoid cycles with dead threads */
  23. } op;
  24. TValue value; /* the value (when closed) */
  25. } u;
  26. };
  27. #define upisopen(up) ((up)->v != &(up)->u.value)
  28. LUAI_FUNC Proto *luaF_newproto (lua_State *L);
  29. LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems);
  30. LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems);
  31. LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
  32. LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
  33. LUAI_FUNC void luaF_close (lua_State *L, StkId level);
  34. LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
  35. LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
  36. int pc);
  37. #endif