| 131 | |
| 132 | |
| 133 | static int str_byte (lua_State *L) { |
| 134 | size_t l; |
| 135 | const char *s = luaL_checklstring(L, 1, &l); |
| 136 | size_t posi = posrelat(luaL_optinteger(L, 2, 1), l); |
| 137 | size_t pose = posrelat(luaL_optinteger(L, 3, posi), l); |
| 138 | int n, i; |
| 139 | if (posi < 1) posi = 1; |
| 140 | if (pose > l) pose = l; |
| 141 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 142 | n = (int)(pose - posi + 1); |
| 143 | if (posi + n <= pose) /* (size_t -> int) overflow? */ |
| 144 | return luaL_error(L, "string slice too long"); |
| 145 | luaL_checkstack(L, n, "string slice too long"); |
| 146 | for (i=0; i<n; i++) |
| 147 | lua_pushinteger(L, uchar(s[posi+i-1])); |
| 148 | return n; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static int str_char (lua_State *L) { |
nothing calls this directly
no test coverage detected