aboutsummaryrefslogtreecommitdiff
path: root/lfunc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lfunc.c')
-rw-r--r--lfunc.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lfunc.c b/lfunc.c
index 685d7bdd..9d0703e1 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lfunc.c,v 2.39 2014/02/13 12:11:34 roberto Exp roberto $ 2** $Id: lfunc.c,v 2.40 2014/02/15 13:12:01 roberto Exp roberto $
3** Auxiliary functions to manipulate prototypes and closures 3** Auxiliary functions to manipulate prototypes and closures
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -35,7 +35,9 @@ Closure *luaF_newLclosure (lua_State *L, int n) {
35 return c; 35 return c;
36} 36}
37 37
38 38/*
39** fill a closure with new closed upvalues
40*/
39void luaF_initupvals (lua_State *L, LClosure *cl) { 41void luaF_initupvals (lua_State *L, LClosure *cl) {
40 int i; 42 int i;
41 for (i = 0; i < cl->nupvalues; i++) { 43 for (i = 0; i < cl->nupvalues; i++) {
@@ -52,18 +54,24 @@ UpVal *luaF_findupval (lua_State *L, StkId level) {
52 UpVal **pp = &L->openupval; 54 UpVal **pp = &L->openupval;
53 UpVal *p; 55 UpVal *p;
54 UpVal *uv; 56 UpVal *uv;
57 lua_assert(isintwups(L) || L->openupval == NULL);
55 while (*pp != NULL && (p = *pp)->v >= level) { 58 while (*pp != NULL && (p = *pp)->v >= level) {
56 lua_assert(upisopen(p)); 59 lua_assert(upisopen(p));
57 if (p->v == level) /* found a corresponding upvalue? */ 60 if (p->v == level) /* found a corresponding upvalue? */
58 return p; /* return it */ 61 return p; /* return it */
59 pp = &p->u.open.next; 62 pp = &p->u.open.next;
60 } 63 }
61 /* not found: create a new one */ 64 /* not found: create a new upvalue */
62 uv = luaM_new(L, UpVal); 65 uv = luaM_new(L, UpVal);
63 uv->refcount = 0; 66 uv->refcount = 0;
64 uv->u.open.next = *pp; 67 uv->u.open.next = *pp; /* link it to list of open upvalues */
68 uv->u.open.touched = 1;
65 *pp = uv; 69 *pp = uv;
66 uv->v = level; /* current value lives in the stack */ 70 uv->v = level; /* current value lives in the stack */
71 if (!isintwups(L)) { /* thread not in list of threads with upvalues? */
72 L->twups = G(L)->twups; /* link it to the list */
73 G(L)->twups = L;
74 }
67 return uv; 75 return uv;
68} 76}
69 77