Minor fixes for Lua 5.22

-Fixed to be compatible with lua 5.22
-Added an #ifdef for Visual Studio compatibility
-Rearranged a couple of variable declarations to be C-compilable.