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