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