** Let x = AB, where A is a prefix of length 'n'. Then, ** rotate x n == BA. But BA == (A^r . B^r)^r. */
| 239 | ** rotate x n == BA. But BA == (A^r . B^r)^r. |
| 240 | */ |
| 241 | LUA_API void lua_rotate (lua_State *L, int idx, int n) { |
| 242 | StkId p, t, m; |
| 243 | lua_lock(L); |
| 244 | t = L->top.p - 1; /* end of stack segment being rotated */ |
| 245 | p = index2stack(L, idx); /* start of segment */ |
| 246 | api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'"); |
| 247 | m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */ |
| 248 | reverse(L, p, m); /* reverse the prefix with length 'n' */ |
| 249 | reverse(L, m + 1, t); /* reverse the suffix */ |
| 250 | reverse(L, p, t); /* reverse the entire segment */ |
| 251 | lua_unlock(L); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | LUA_API void lua_copy (lua_State *L, int fromidx, int toidx) { |
no test coverage detected