Convert lib/index.coffee to JavaScript

I tried to keep as close as possible to the original code. All tests are still passing but I haven't done any further testing. 

The biggest change I've made is to move all Lua scripts into `lib/scripts` as separate `.lua` files.