MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / luaV_concat

Function luaV_concat

other_src/lua/src/lvm.cpp:284–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282
283
284void luaV_concat (lua_State *L, int total, int last) {
285 do {
286 StkId top = L->base + last + 1;
287 int n = 2; /* number of elements handled in this pass (at least 2) */
288 if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
289 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
290 luaG_concaterror(L, top-2, top-1);
291 } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
292 (void)tostring(L, top - 2); /* result is first op (as string) */
293 else {
294 /* at least two string values; get as many as possible */
295 size_t tl = tsvalue(top-1)->len;
296 char *buffer;
297 int i;
298 /* collect total length */
299 for (n = 1; n < total && tostring(L, top-n-1); n++) {
300 size_t l = tsvalue(top-n-1)->len;
301 if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
302 tl += l;
303 }
304 buffer = luaZ_openspace(L, &G(L)->buff, tl);
305 tl = 0;
306 for (i=n; i>0; i--) { /* concat all strings */
307 size_t l = tsvalue(top-i)->len;
308 memcpy(buffer+tl, svalue(top-i), l);
309 tl += l;
310 }
311 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
312 }
313 total -= n-1; /* got `n' strings to create 1 new */
314 last -= n-1;
315 } while (total > 1); /* repeat until only 1 result left */
316}
317
318
319static void Arith (lua_State *L, StkId ra, const TValue *rb,

Callers 3

luaV_executeFunction · 0.70
luaO_pushvfstringFunction · 0.70
lua_concatFunction · 0.70

Calls 6

tostringFunction · 0.85
call_binTMFunction · 0.70
luaG_concaterrorFunction · 0.70
luaG_runerrorFunction · 0.70
luaZ_openspaceFunction · 0.70
luaS_newlstrFunction · 0.70

Tested by

no test coverage detected