Lua 5.2 compatibility

There is some patches to fix compatibility for Lua 5.1 & 5.2. Not fully tested but seems to work well with my test cases under 5.1.5, 5.2.1, JIT 2.0.0 (with and without 5.2 compat).