** Return true iff value at stack index 'a' is less than the value at ** index 'b' (according to the order of the sort). */
| 271 | ** index 'b' (according to the order of the sort). |
| 272 | */ |
| 273 | static int sort_comp (lua_State *L, int a, int b) { |
| 274 | if (lua_isnil(L, 2)) /* no function? */ |
| 275 | return lua_compare(L, a, b, LUA_OPLT); /* a < b */ |
| 276 | else { /* function */ |
| 277 | int res; |
| 278 | lua_pushvalue(L, 2); /* push function */ |
| 279 | lua_pushvalue(L, a-1); /* -1 to compensate function */ |
| 280 | lua_pushvalue(L, b-2); /* -2 to compensate function and 'a' */ |
| 281 | lua_call(L, 2, 1); /* call function */ |
| 282 | res = lua_toboolean(L, -1); /* get result */ |
| 283 | lua_pop(L, 1); /* pop result */ |
| 284 | return res; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | /* |
no test coverage detected