MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaX_newstring

Function luaX_newstring

depends/lua/src/llex.c:127–144  ·  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) */

Source from the content-addressed store, hash-verified

125** (by that time it should be anchored somewhere)
126*/
127TString *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/*

Callers 4

read_long_stringFunction · 0.85
read_stringFunction · 0.85
llexFunction · 0.85
new_localvarliteral_Function · 0.85

Calls 2

luaS_newlstrFunction · 0.85
luaH_setFunction · 0.85

Tested by

no test coverage detected