MCPcopy Create free account
hub / github.com/RomanKubiak/ctrlr / str_byte

Function str_byte

Source/Misc/lua/src/lua.c:13783–13799  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13781
13782
13783static int str_byte (lua_State *L) {
13784size_t l;
13785const char *s = luaL_checklstring(L, 1, &l);
13786ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l);
13787ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l);
13788int n, i;
13789if (posi <= 0) posi = 1;
13790if ((size_t)pose > l) pose = l;
13791if (posi > pose) return 0; /* empty interval; return no values */
13792n = (int)(pose - posi + 1);
13793if (posi + n <= pose) /* overflow? */
13794luaL_error(L, "string slice too long");
13795luaL_checkstack(L, n, "string slice too long");
13796for (i=0; i<n; i++)
13797lua_pushinteger(L, uchar(s[posi+i-1]));
13798return n;
13799}
13800
13801
13802static int str_char (lua_State *L) {

Callers

nothing calls this directly

Calls 6

luaL_checklstringFunction · 0.85
posrelatFunction · 0.85
luaL_optintegerFunction · 0.85
luaL_errorFunction · 0.85
luaL_checkstackFunction · 0.85
lua_pushintegerFunction · 0.85

Tested by

no test coverage detected