Clean lua 5.2

Merging my changes to add Lua 5.2 support and fix some code quality issues.