** Let x = AB, where A is a prefix of length 'n'. Then, ** rotate x n == BA. But BA == (A^r . B^r)^r. */
| 212 | ** rotate x n == BA. But BA == (A^r . B^r)^r. |
| 213 | */ |
| 214 | LUA_API void lua_rotate (lua_State *L, int idx, int n) { |
| 215 | StkId p, t, m; |
| 216 | lua_lock(L); |
| 217 | t = L->top - 1; /* end of stack segment being rotated */ |
| 218 | p = index2stack(L, idx); /* start of segment */ |
| 219 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
| 220 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
| 221 | reverse(L, p, m); /* reverse the prefix with length 'n' */ |
| 222 | reverse(L, m + 1, t); /* reverse the suffix */ |
| 223 | reverse(L, p, t); /* reverse the entire segment */ |
| 224 | lua_unlock(L); |
| 225 | } |
| 226 | |
| 227 | |
| 228 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { |
no test coverage detected