MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaSortArray

Function luaSortArray

app/redis-6.2.6/src/scripting.c:326–349  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

324 * The array is sorted using table.sort itself, and assuming all the
325 * list elements are strings. */
326void 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.

Callers 1

luaRedisGenericCommandFunction · 0.85

Calls 6

lua_getglobalFunction · 0.85
lua_pcallFunction · 0.85
lua_callFunction · 0.85
lua_pushstringFunction · 0.50
lua_gettableFunction · 0.50
lua_pushvalueFunction · 0.50

Tested by

no test coverage detected