| 164 | |
| 165 | |
| 166 | static int str_byte (lua_State *L) { |
| 167 | size_t l; |
| 168 | const char *s = luaL_checklstring(L, 1, &l); |
| 169 | lua_Integer pi = luaL_optinteger(L, 2, 1); |
| 170 | size_t posi = posrelatI(pi, l); |
| 171 | size_t pose = getendpos(L, 3, pi, l); |
| 172 | int n, i; |
| 173 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 174 | if (l_unlikely(pose - posi >= (size_t)INT_MAX)) /* arithmetic overflow? */ |
| 175 | return luaL_error(L, "string slice too long"); |
| 176 | n = (int)(pose - posi) + 1; |
| 177 | luaL_checkstack(L, n, "string slice too long"); |
| 178 | for (i=0; i<n; i++) |
| 179 | lua_pushinteger(L, cast_uchar(s[posi + cast_uint(i) - 1])); |
| 180 | return n; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | static int str_char (lua_State *L) { |
nothing calls this directly
no test coverage detected