MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / str_byte

Function str_byte

extlibs/lua/src/lstrlib.c:176–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected