** creates a new string and anchors it 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) */
| 128 | ** (by that time it should be anchored somewhere) |
| 129 | */ |
| 130 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { |
| 131 | lua_State *L = ls->L; |
| 132 | TValue *o; /* entry for 'str' */ |
| 133 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 134 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 135 | o = luaH_set(L, ls->h, s2v(L->top - 1)); |
| 136 | if (isempty(o)) { /* not in use yet? */ |
| 137 | /* boolean value does not need GC barrier; |
| 138 | table is not a metatable, so it does not need to invalidate cache */ |
| 139 | setbtvalue(o); /* t[string] = true */ |
| 140 | luaC_checkGC(L); |
| 141 | } |
| 142 | else { /* string already present */ |
| 143 | ts = keystrval(nodefromval(o)); /* re-use value previously stored */ |
| 144 | } |
| 145 | L->top--; /* remove string from stack */ |
| 146 | return ts; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /* |
no test coverage detected