Sort the array currently in the stack. We do this to make the output * of commands like KEYS or SMEMBERS something deterministic when called * from Lua (to play well with AOf/replication). * * The array is sorted using table.sort itself, and assuming all the * list elements are strings. */
| 324 | * The array is sorted using table.sort itself, and assuming all the |
| 325 | * list elements are strings. */ |
| 326 | void luaSortArray(lua_State *lua) { |
| 327 | /* Initial Stack: array */ |
| 328 | lua_getglobal(lua,"table"); |
| 329 | lua_pushstring(lua,"sort"); |
| 330 | lua_gettable(lua,-2); /* Stack: array, table, table.sort */ |
| 331 | lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ |
| 332 | if (lua_pcall(lua,1,0,0)) { |
| 333 | /* Stack: array, table, error */ |
| 334 | |
| 335 | /* We are not interested in the error, we assume that the problem is |
| 336 | * that there are 'false' elements inside the array, so we try |
| 337 | * again with a slower function but able to handle this case, that |
| 338 | * is: table.sort(table, __redis__compare_helper) */ |
| 339 | lua_pop(lua,1); /* Stack: array, table */ |
| 340 | lua_pushstring(lua,"sort"); /* Stack: array, table, sort */ |
| 341 | lua_gettable(lua,-2); /* Stack: array, table, table.sort */ |
| 342 | lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ |
| 343 | lua_getglobal(lua,"__redis__compare_helper"); |
| 344 | /* Stack: array, table, table.sort, array, __redis__compare_helper */ |
| 345 | lua_call(lua,2,0); |
| 346 | } |
| 347 | /* Stack: array (sorted), table */ |
| 348 | lua_pop(lua,1); /* Stack: array (sorted) */ |
| 349 | } |
| 350 | |
| 351 | /* --------------------------------------------------------------------------- |
| 352 | * Lua reply to Redis reply conversion functions. |
no test coverage detected