Fix Lua stack overflow during save

Fixes #2977 (possibly... needs checking)

LuaRef::Save leaks its value into the Lua stack, which can lead to a Lua stack overflow during serialisation. This turns on LUA_USE_APICHECK to catch Lua stack overflows more reliably instead of just letting them corrupt the heap which is how this bug was found. It also fixes the stack leak in LuaRef::Save.

Apart from that, LuaSerializer::pickle operates recursively and so can easily overflow the Lua stack. This patch adds the necessary lua_checkstack call to grow the stack as necessary during recursive pickling.

It is possible (likely?) that there are stack leaks remaining in other places. It would be good to add LUA_DEBUG_START/LUA_DEBUG_END in more places to check for that. At least with LUA_USE_APICHECK enabled, Lua stack overflows should be much easier to diagnose.

CC @laarmen (maybe you could check other parts of LuaRef?)