Neopallium/luvit — comment on commit a380973695f06d1027d3c8546437e63b4e53bcdf
File:  line 0
By Neopallium:

Here is the logic used to detect the c modules path:
function ffi_load_cmodule(name, global)
for path,module in pairs(package.loaded) do
if type(module) == 'string' and path:match(name) == name then
local C, err = ffi.load(path, global)
-- return opened library
if C then return C end
end
end
error("Failed to find: " .. name)
end

That Lua code is embedded in the C module and is run only if the VM loading the module has FFI support (i.e. only LuaJIT based VMs)
Most of my C modules are hybrids that have both normal C API based bindings and FFI based bindings.