| 13781 | |
| 13782 | |
| 13783 | static int str_byte (lua_State *L) { |
| 13784 | size_t l; |
| 13785 | const char *s = luaL_checklstring(L, 1, &l); |
| 13786 | ptrdiff_t posi = posrelat(luaL_optinteger(L, 2, 1), l); |
| 13787 | ptrdiff_t pose = posrelat(luaL_optinteger(L, 3, posi), l); |
| 13788 | int n, i; |
| 13789 | if (posi <= 0) posi = 1; |
| 13790 | if ((size_t)pose > l) pose = l; |
| 13791 | if (posi > pose) return 0; /* empty interval; return no values */ |
| 13792 | n = (int)(pose - posi + 1); |
| 13793 | if (posi + n <= pose) /* overflow? */ |
| 13794 | luaL_error(L, "string slice too long"); |
| 13795 | luaL_checkstack(L, n, "string slice too long"); |
| 13796 | for (i=0; i<n; i++) |
| 13797 | lua_pushinteger(L, uchar(s[posi+i-1])); |
| 13798 | return n; |
| 13799 | } |
| 13800 | |
| 13801 | |
| 13802 | static int str_char (lua_State *L) { |
nothing calls this directly
no test coverage detected