MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / str_rep

Function str_rep

src/Chain/libraries/glua/lstrlib.cpp:121–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected