Unlike "decode", encoding leaves both the key/value on the stack before descending. This leaves no spare room for luaL_error() in case the depth check or lua_checkstack() fails. Allocate an extra stack slot to ensure there is always room for luaL_error() in json_check_encode_depth(). Note: this would not have caused a crash or fault due to the EXTRA_STACK slot reserve, but it was a misuse of the Lua C API.
Return boolean values from configuration functions to simplify usage in the common case. Eg,: if not cjson.encode_invalid_numbers() then .. end
Include depth and character index when throwing decode nesting errors. Pre-emptively add a test decoding a massively nested JSON array. Lua stack overflow faults are unlikely to occur on simple data structures. Valgrind can highlight stack allocation bugs with complicated JSON even if the test succeeds.