xref: /minix/external/mit/lua/dist/src/lfunc.h (revision 0a6a1f1d)
1 /*	$NetBSD: lfunc.h,v 1.3 2015/10/08 13:21:00 mbalmer Exp $	*/
2 
3 /*
4 ** Id: lfunc.h,v 2.15 2015/01/13 15:49:11 roberto Exp
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, sizeof(CClosure)) + \
17                          cast(int, sizeof(TValue)*((n)-1)))
18 
19 #define sizeLclosure(n)	(cast(int, sizeof(LClosure)) + \
20                          cast(int, sizeof(TValue *)*((n)-1)))
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 /*
35 ** Upvalues for Lua closures
36 */
37 struct UpVal {
38   TValue *v;  /* points to stack or to its own value */
39   lu_mem refcount;  /* reference counter */
40   union {
41     struct {  /* (when open) */
42       UpVal *next;  /* linked list */
43       int touched;  /* mark to avoid cycles with dead threads */
44     } open;
45     TValue value;  /* the value (when closed) */
46   } u;
47 };
48 
49 #define upisopen(up)	((up)->v != &(up)->u.value)
50 
51 
52 LUAI_FUNC Proto *luaF_newproto (lua_State *L);
53 LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nelems);
54 LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nelems);
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_close (lua_State *L, StkId level);
58 LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
59 LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
60                                          int pc);
61 
62 
63 #endif
64