MCPcopy Create free account
hub / github.com/BigPig0/RelayLive / str_rep

Function str_rep

ThirdParty/lua/lua/lstrlib.c:117–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115
116
117static int str_rep (lua_State *L) {
118 size_t l, lsep;
119 const char *s = luaL_checklstring(L, 1, &l);
120 lua_Integer n = luaL_checkinteger(L, 2);
121 const char *sep = luaL_optlstring(L, 3, "", &lsep);
122 if (n <= 0) lua_pushliteral(L, "");
123 else if (l + lsep < l || l + lsep > MAXSIZE / n) /* may overflow? */
124 return luaL_error(L, "resulting string too large");
125 else {
126 size_t totallen = (size_t)n * l + (size_t)(n - 1) * lsep;
127 luaL_Buffer b;
128 char *p = luaL_buffinitsize(L, &b, totallen);
129 while (n-- > 1) { /* first n-1 copies (followed by separator) */
130 memcpy(p, s, l * sizeof(char)); p += l;
131 if (lsep > 0) { /* empty 'memcpy' is not that cheap */
132 memcpy(p, sep, lsep * sizeof(char));
133 p += lsep;
134 }
135 }
136 memcpy(p, s, l * sizeof(char)); /* last copy (not followed by separator) */
137 luaL_pushresultsize(&b, totallen);
138 }
139 return 1;
140}
141
142
143static int str_byte (lua_State *L) {

Callers

nothing calls this directly

Calls 6

luaL_checklstringFunction · 0.85
luaL_checkintegerFunction · 0.85
luaL_optlstringFunction · 0.85
luaL_errorFunction · 0.85
luaL_buffinitsizeFunction · 0.85
luaL_pushresultsizeFunction · 0.85

Tested by

no test coverage detected