2 ** $Id: lfunc.c,v 1.9 1998/06/19 16:14:09 roberto Exp $
3 ** Auxiliary functions to manipulate prototypes and closures
4 ** See Copyright Notice in lua.h
14 #define gcsizeproto(p) 5 /* approximate "weight" for a prototype */
15 #define gcsizeclosure(c) 1 /* approximate "weight" for a closure */
19 Closure
*luaF_newclosure (int nelems
)
21 Closure
*c
= (Closure
*)luaM_malloc(sizeof(Closure
)+nelems
*sizeof(TObject
));
22 luaO_insertlist(&(L
->rootcl
), (GCnode
*)c
);
23 L
->nblocks
+= gcsizeclosure(c
);
29 TProtoFunc
*luaF_newproto (void)
31 TProtoFunc
*f
= luaM_new(TProtoFunc
);
38 luaO_insertlist(&(L
->rootproto
), (GCnode
*)f
);
39 L
->nblocks
+= gcsizeproto(f
);
45 static void freefunc (TProtoFunc
*f
)
48 luaM_free(f
->locvars
);
54 void luaF_freeproto (TProtoFunc
*l
)
57 TProtoFunc
*next
= (TProtoFunc
*)l
->head
.next
;
58 L
->nblocks
-= gcsizeproto(l
);
65 void luaF_freeclosure (Closure
*l
)
68 Closure
*next
= (Closure
*)l
->head
.next
;
69 L
->nblocks
-= gcsizeclosure(l
);
77 ** Look for n-th local variable at line "line" in function "func".
78 ** Returns NULL if not found.
80 char *luaF_getlocalname (TProtoFunc
*func
, int local_number
, int line
)
84 LocVar
*lv
= func
->locvars
;
87 for (; lv
->line
!= -1 && lv
->line
< line
; lv
++) {
88 if (lv
->varname
) { /* register */
89 if (++count
== local_number
)
90 varname
= lv
->varname
->str
;
93 if (--count
< local_number
)