luci-lib-jsonc: improve handling of integral numeric values
Properly deal with integral numeric values exceeding the int32_t range
by replacing the cast logic with more fine grained checks:
- Lua numbers which are integers in the first place are directly converted
to JSON integers
- Finite double Lua numbers which are integral are converted to JSON
integer values
- All other numeric values are converted to JSON doubles
This should bring the handling of large integral value in line with the
documented behavior of turning non-fractional Lua numbers into JSON
integers.
Fixes: #6647
Signed-off-by: Jo-Philipp Wich <jo@mein.io>