I was working on this a bit when I noticed your package that does it already. Lua has a built in way to extend `require` so replacing it shouldn't be necessary. I was doing it [here](https://github.com/dannyfritz/commonjs-lua/blob/01ed52/commonjs.lua#L28). It is done using [package.loaders](http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders).