MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / anchorstr

Function anchorstr

third-party/lua-5.5.0/src/llex.c:135–150  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

133** one copy of each unique string.
134*/
135static 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/*

Callers 2

luaX_newstringFunction · 0.85
llexFunction · 0.85

Calls 2

luaH_getstrFunction · 0.70
luaH_setFunction · 0.70

Tested by

no test coverage detected