Home | History | Annotate | Line # | Download | only in src
      1 /*	$NetBSD: lfunc.h,v 1.11 2023/06/08 21:12:08 nikita Exp $	*/
      2 
      3 /*
      4 ** Id: lfunc.h
      5 ** Auxiliary functions to manipulate prototypes and closures
      6 ** See Copyright Notice in lua.h
      7 */
      8 
      9 #ifndef lfunc_h
     10 #define lfunc_h
     11 
     12 
     13 #include "lobject.h"
     14 
     15 
     16 #define sizeCclosure(n)	(cast_int(offsetof(CClosure, upvalue)) + \
     17                          cast_int(sizeof(TValue)) * (n))
     18 
     19 #define sizeLclosure(n)	(cast_int(offsetof(LClosure, upvals)) + \
     20                          cast_int(sizeof(TValue *)) * (n))
     21 
     22 
     23 /* test whether thread is in 'twups' list */
     24 #define isintwups(L)	(L->twups != L)
     25 
     26 
     27 /*
     28 ** maximum number of upvalues in a closure (both C and Lua). (Value
     29 ** must fit in a VM register.)
     30 */
     31 #define MAXUPVAL	255
     32 
     33 
     34 #define upisopen(up)	((up)->v.p != &(up)->u.value)
     35 
     36 
     37 #define uplevel(up)	check_exp(upisopen(up), cast(StkId, (up)->v.p))
     38 
     39 
     40 /*
     41 ** maximum number of misses before giving up the cache of closures
     42 ** in prototypes
     43 */
     44 #define MAXMISS		10
     45 
     46 
     47 
     48 /* special status to close upvalues preserving the top of the stack */
     49 #define CLOSEKTOP	(-1)
     50 
     51 
     52 LUAI_FUNC Proto *luaF_newproto (lua_State *L);
     53 LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);
     54 LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
     55 LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
     56 LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
     57 LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
     58 LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
     59 LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
     60 LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
     61 LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
     62 LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
     63                                          int pc);
     64 
     65 
     66 #endif
     67