| 174 | |
| 175 | |
| 176 | static 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 | |
| 194 | static int str_char (lua_State *L) { |
nothing calls this directly
no test coverage detected