xref: /freebsd/contrib/lua/src/lfunc.h (revision a9490b81b032b43cdb3c8c76b4d01bbad9ff82c1)
18e3e3a7aSWarner Losh /*
20495ed39SKyle Evans ** $Id: lfunc.h $
38e3e3a7aSWarner Losh ** Auxiliary functions to manipulate prototypes and closures
48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h
58e3e3a7aSWarner Losh */
68e3e3a7aSWarner Losh 
78e3e3a7aSWarner Losh #ifndef lfunc_h
88e3e3a7aSWarner Losh #define lfunc_h
98e3e3a7aSWarner Losh 
108e3e3a7aSWarner Losh 
118e3e3a7aSWarner Losh #include "lobject.h"
128e3e3a7aSWarner Losh 
138e3e3a7aSWarner Losh 
140495ed39SKyle Evans #define sizeCclosure(n)	(cast_int(offsetof(CClosure, upvalue)) + \
150495ed39SKyle Evans                          cast_int(sizeof(TValue)) * (n))
168e3e3a7aSWarner Losh 
170495ed39SKyle Evans #define sizeLclosure(n)	(cast_int(offsetof(LClosure, upvals)) + \
180495ed39SKyle Evans                          cast_int(sizeof(TValue *)) * (n))
198e3e3a7aSWarner Losh 
208e3e3a7aSWarner Losh 
218e3e3a7aSWarner Losh /* test whether thread is in 'twups' list */
228e3e3a7aSWarner Losh #define isintwups(L)	(L->twups != L)
238e3e3a7aSWarner Losh 
248e3e3a7aSWarner Losh 
258e3e3a7aSWarner Losh /*
268e3e3a7aSWarner Losh ** maximum number of upvalues in a closure (both C and Lua). (Value
278e3e3a7aSWarner Losh ** must fit in a VM register.)
288e3e3a7aSWarner Losh */
298e3e3a7aSWarner Losh #define MAXUPVAL	255
308e3e3a7aSWarner Losh 
318e3e3a7aSWarner Losh 
32*a9490b81SWarner Losh #define upisopen(up)	((up)->v.p != &(up)->u.value)
338e3e3a7aSWarner Losh 
348e3e3a7aSWarner Losh 
35*a9490b81SWarner Losh #define uplevel(up)	check_exp(upisopen(up), cast(StkId, (up)->v.p))
360495ed39SKyle Evans 
370495ed39SKyle Evans 
380495ed39SKyle Evans /*
390495ed39SKyle Evans ** maximum number of misses before giving up the cache of closures
400495ed39SKyle Evans ** in prototypes
410495ed39SKyle Evans */
420495ed39SKyle Evans #define MAXMISS		10
430495ed39SKyle Evans 
440495ed39SKyle Evans 
450495ed39SKyle Evans 
468c784bb8SWarner Losh /* special status to close upvalues preserving the top of the stack */
478c784bb8SWarner Losh #define CLOSEKTOP	(-1)
480495ed39SKyle Evans 
490495ed39SKyle Evans 
508e3e3a7aSWarner Losh LUAI_FUNC Proto *luaF_newproto (lua_State *L);
510495ed39SKyle Evans LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals);
520495ed39SKyle Evans LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals);
538e3e3a7aSWarner Losh LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl);
548e3e3a7aSWarner Losh LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
550495ed39SKyle Evans LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level);
568c784bb8SWarner Losh LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level);
57*a9490b81SWarner Losh LUAI_FUNC StkId luaF_close (lua_State *L, StkId level, int status, int yy);
580495ed39SKyle Evans LUAI_FUNC void luaF_unlinkupval (UpVal *uv);
598e3e3a7aSWarner Losh LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
608e3e3a7aSWarner Losh LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
618e3e3a7aSWarner Losh                                          int pc);
628e3e3a7aSWarner Losh 
638e3e3a7aSWarner Losh 
648e3e3a7aSWarner Losh #endif
65