MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / luaX_newstring

Function luaX_newstring

lib/lua/src/llex.c:134–149  ·  view source on GitHub ↗

** 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. It also internalizes long strings, ** ensuring there is only one copy of each unique string. The table ** here is used as a set: the string enters as the key, while its value ** is irrelevant. We use the string itself as t

Source from the content-addressed store, hash-verified

132** this value.
133*/
134TString *luaX_newstring (LexState *ls, const char *str, size_t l) {
135 lua_State *L = ls->L;
136 TString *ts = luaS_newlstr(L, str, l); /* create new string */
137 const TValue *o = luaH_getstr(ls->h, ts);
138 if (!ttisnil(o)) /* string already present? */
139 ts = keystrval(nodefromval(o)); /* get saved copy */
140 else { /* not in use yet */
141 TValue *stv = s2v(L->top.p++); /* reserve stack space for string */
142 setsvalue(L, stv, ts); /* temporarily anchor the string */
143 luaH_finishset(L, ls->h, stv, o, stv); /* t[string] = string */
144 /* table is not a metatable, so it does not need to invalidate cache */
145 luaC_checkGC(L);
146 L->top.p--; /* remove string from stack */
147 }
148 return ts;
149}
150
151
152/*

Callers 3

read_long_stringFunction · 0.85
read_stringFunction · 0.85
llexFunction · 0.85

Calls 3

luaS_newlstrFunction · 0.85
luaH_getstrFunction · 0.85
luaH_finishsetFunction · 0.85

Tested by

no test coverage detected