Fixed Lua 5.1 library detection failed on Gentoo and derivatives

as discussed in #6529.