move lua sort to c++