diff options
Diffstat (limited to 'lfunc.c')
-rw-r--r-- | lfunc.c | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lfunc.c,v 1.28 2000/08/08 20:42:07 roberto Exp roberto $ | 2 | ** $Id: lfunc.c,v 1.29 2000/08/09 19:16:57 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 | */ |
@@ -43,6 +43,7 @@ Proto *luaF_newproto (lua_State *L) { | |||
43 | f->kproto = NULL; | 43 | f->kproto = NULL; |
44 | f->nkproto = 0; | 44 | f->nkproto = 0; |
45 | f->locvars = NULL; | 45 | f->locvars = NULL; |
46 | f->nlocvars = 0; | ||
46 | f->next = L->rootproto; | 47 | f->next = L->rootproto; |
47 | L->rootproto = f; | 48 | L->rootproto = f; |
48 | f->marked = 0; | 49 | f->marked = 0; |
@@ -73,19 +74,15 @@ void luaF_freeclosure (lua_State *L, Closure *c) { | |||
73 | ** Look for n-th local variable at line `line' in function `func'. | 74 | ** Look for n-th local variable at line `line' in function `func'. |
74 | ** Returns NULL if not found. | 75 | ** Returns NULL if not found. |
75 | */ | 76 | */ |
76 | const char *luaF_getlocalname (const Proto *func, int local_number, int pc) { | 77 | const char *luaF_getlocalname (const Proto *f, int local_number, int pc) { |
77 | int count = 0; | 78 | int i; |
78 | const char *varname = NULL; | 79 | for (i = 0; i<f->nlocvars && f->locvars[i].startpc <= pc; i++) { |
79 | LocVar *lv = func->locvars; | 80 | if (pc < f->locvars[i].endpc) { /* is variable active? */ |
80 | for (; lv->pc != -1 && lv->pc <= pc; lv++) { | 81 | local_number--; |
81 | if (lv->varname) { /* register */ | 82 | if (local_number == 0) |
82 | if (++count == local_number) | 83 | return f->locvars[i].varname->str; |
83 | varname = lv->varname->str; | ||
84 | } | 84 | } |
85 | else /* unregister */ | ||
86 | if (--count < local_number) | ||
87 | varname = NULL; | ||
88 | } | 85 | } |
89 | return varname; | 86 | return NULL; /* not found */ |
90 | } | 87 | } |
91 | 88 | ||