MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / str_byte

Function str_byte

lib/lua/src/lstrlib.c:177–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175
176
177static int str_byte (lua_State *L) {
178 size_t l;
179 const char *s = luaL_checklstring(L, 1, &l);
180 lua_Integer pi = luaL_optinteger(L, 2, 1);
181 size_t posi = posrelatI(pi, l);
182 size_t pose = getendpos(L, 3, pi, l);
183 int n, i;
184 if (posi > pose) return 0; /* empty interval; return no values */
185 if (l_unlikely(pose - posi >= (size_t)INT_MAX)) /* arithmetic overflow? */
186 return luaL_error(L, "string slice too long");
187 n = (int)(pose - posi) + 1;
188 luaL_checkstack(L, n, "string slice too long");
189 for (i=0; i<n; i++)
190 lua_pushinteger(L, uchar(s[posi+i-1]));
191 return n;
192}
193
194
195static int str_char (lua_State *L) {

Callers

nothing calls this directly

Calls 7

luaL_checklstringFunction · 0.85
luaL_optintegerFunction · 0.85
posrelatIFunction · 0.85
getendposFunction · 0.85
luaL_errorFunction · 0.85
luaL_checkstackFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected