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