** creates a new string and anchors it in function's table so that ** it will not be collected until the end of the function's compilation ** (by that time it should be anchored in function's prototype) */
| 122 | ** (by that time it should be anchored in function's prototype) |
| 123 | */ |
| 124 | TString *luaX_newstring (LexState *ls, const char *str, size_t l) { |
| 125 | lua_State *L = ls->L; |
| 126 | TValue *o; /* entry for `str' */ |
| 127 | TString *ts = luaS_newlstr(L, str, l); /* create new string */ |
| 128 | setsvalue2s(L, L->top++, ts); /* temporarily anchor it in stack */ |
| 129 | o = luaH_set(L, ls->fs->h, L->top - 1); |
| 130 | if (ttisnil(o)) { /* not in use yet? (see 'addK') */ |
| 131 | /* boolean value does not need GC barrier; |
| 132 | table has no metatable, so it does not need to invalidate cache */ |
| 133 | setbvalue(o, 1); /* t[string] = true */ |
| 134 | luaC_checkGC(L); |
| 135 | } |
| 136 | else { /* string already present */ |
| 137 | ts = rawtsvalue(keyfromval(o)); /* re-use value previously stored */ |
| 138 | } |
| 139 | L->top--; /* remove string from stack */ |
| 140 | return ts; |
| 141 | } |
| 142 | |
| 143 | |
| 144 | /* |
no test coverage detected