MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / luaV_concat

Function luaV_concat

Source/Misc/lua/src/lua.c:15111–15143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15109
15110
15111void luaV_concat (lua_State *L, int total, int last) {
15112do {
15113StkId top = L->base + last + 1;
15114int n = 2; /* number of elements handled in this pass (at least 2) */
15115if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
15116if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
15117luaG_concaterror(L, top-2, top-1);
15118} else if (tsvalue(top-1)->len == 0) /* second op is empty? */
15119(void)tostring(L, top - 2); /* result is first op (as string) */
15120else {
15121/* at least two string values; get as many as possible */
15122size_t tl = tsvalue(top-1)->len;
15123char *buffer;
15124int i;
15125/* collect total length */
15126for (n = 1; n < total && tostring(L, top-n-1); n++) {
15127size_t l = tsvalue(top-n-1)->len;
15128if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
15129tl += l;
15130}
15131buffer = luaZ_openspace(L, &G(L)->buff, tl);
15132tl = 0;
15133for (i=n; i>0; i--) { /* concat all strings */
15134size_t l = tsvalue(top-i)->len;
15135memcpy(buffer+tl, svalue(top-i), l);
15136tl += l;
15137}
15138setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
15139}
15140total -= n-1; /* got `n' strings to create 1 new */
15141last -= n-1;
15142} while (total > 1); /* repeat until only 1 result left */
15143}
15144
15145
15146static void Arith (lua_State *L, StkId ra, const TValue *rb,

Callers 3

lua_concatFunction · 0.85
luaO_pushvfstringFunction · 0.85
luaV_executeFunction · 0.85

Calls 5

call_binTMFunction · 0.85
luaG_concaterrorFunction · 0.85
luaG_runerrorFunction · 0.85
luaZ_openspaceFunction · 0.85
luaS_newlstrFunction · 0.85

Tested by

no test coverage detected