1 /* 2 ** $Id: lfunc.h,v 2.14 2014/06/19 18:27:20 roberto Exp $ 3 ** Auxiliary functions to manipulate prototypes and closures 4 ** See Copyright Notice in lua.h 5 */ 6 7 #ifndef lfunc_h 8 #define lfunc_h 9 10 11 #include "lobject.h" 12 13 14 #define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ 15 cast(int, sizeof(TValue)*((n)-1))) 16 17 #define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ 18 cast(int, sizeof(TValue *)*((n)-1))) 19 20 21 /* test whether thread is in 'twups' list */ 22 #define isintwups(L) (L->twups != L) 23 24 25 /* 26 ** Upvalues for Lua closures 27 */ 28 struct UpVal { 29 TValue *v; /* points to stack or to its own value */ 30 lu_mem refcount; /* reference counter */ 31 union { 32 struct { /* (when open) */ 33 UpVal *next; /* linked list */ 34 int touched; /* mark to avoid cycles with dead threads */ 35 } open; 36 TValue value; /* the value (when closed) */ 37 } u; 38 }; 39 40 #define upisopen(up) ((up)->v != &(up)->u.value) 41 42 43 LUAI_FUNC Proto *luaF_newproto (lua_State *L); 44 LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems); 45 LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems); 46 LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 47 LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 48 LUAI_FUNC void luaF_close (lua_State *L, StkId level); 49 LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 50 LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 51 int pc); 52 53 54 #endif 55