| 146 | |
| 147 | |
| 148 | static int str_byte (lua_State *L) { |
| 149 | size_t l; |
| 150 | const char *s = luaL_checklstring(L, 1, &l); |
| 151 | lua_Integer posi = posrelat(luaL_optinteger(L, 2, 1), l); |
| 152 | lua_Integer pose = posrelat(luaL_optinteger(L, 3, posi), l); |
| 153 | int n, i; |
| 154 | if (posi < 1) posi = 1; |
| 155 | if (pose > (lua_Integer)l) pose = l; |
| 156 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 157 | if (pose - posi >= INT_MAX) /* arithmetic overflow? */ |
| 158 | return luaL_error(L, "string slice too long"); |
| 159 | n = (int)(pose - posi) + 1; |
| 160 | luaL_checkstack(L, n, "string slice too long"); |
| 161 | for (i=0; i<n; i++) |
| 162 | lua_pushinteger(L, uchar(s[posi+i-1])); |
| 163 | return n; |
| 164 | } |
| 165 | |
| 166 | |
| 167 | static int str_char (lua_State *L) { |
nothing calls this directly
no test coverage detected