** Anchors a string in scanner's table so that it will not be collected ** until the end of the compilation; by that time it should be anchored ** somewhere. It also internalizes long strings, ensuring there is only ** one copy of each unique string. */
| 133 | ** one copy of each unique string. |
| 134 | */ |
| 135 | static TString *anchorstr (LexState *ls, TString *ts) { |
| 136 | lua_State *L = ls->L; |
| 137 | TValue oldts; |
| 138 | int tag = luaH_getstr(ls->h, ts, &oldts); |
| 139 | if (!tagisempty(tag)) /* string already present? */ |
| 140 | return tsvalue(&oldts); /* use stored value */ |
| 141 | else { /* create a new entry */ |
| 142 | TValue *stv = s2v(L->top.p++); /* reserve stack space for string */ |
| 143 | setsvalue(L, stv, ts); /* push (anchor) the string on the stack */ |
| 144 | luaH_set(L, ls->h, stv, stv); /* t[string] = string */ |
| 145 | /* table is not a metatable, so it does not need to invalidate cache */ |
| 146 | luaC_checkGC(L); |
| 147 | L->top.p--; /* remove string from stack */ |
| 148 | return ts; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /* |
no test coverage detected