MCPcopy Create free account
hub / github.com/defold/defold / json_append_number

Function json_append_number

engine/script/src/luacjson/lua_cjson.c:767–803  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

765}
766
767static void json_append_number(lua_State *l, json_config_t *cfg,
768 strbuf_t *json, int lindex)
769{
770 double num = lua_tonumber(l, lindex);
771 int len;
772
773 if (cfg->encode_invalid_numbers == 0) {
774 /* Prevent encoding invalid numbers */
775 if (isinf(num) || isnan(num))
776 json_encode_exception(l, cfg, json, lindex,
777 "must not be NaN or Infinity");
778 } else if (cfg->encode_invalid_numbers == 1) {
779 /* Encode NaN/Infinity separately to ensure Javascript compatible
780 * values are used. */
781 if (isnan(num)) {
782 strbuf_append_mem(json, "NaN", 3);
783 return;
784 }
785 if (isinf(num)) {
786 if (num < 0)
787 strbuf_append_mem(json, "-Infinity", 9);
788 else
789 strbuf_append_mem(json, "Infinity", 8);
790 return;
791 }
792 } else {
793 /* Encode invalid numbers as "null" */
794 if (isinf(num) || isnan(num)) {
795 strbuf_append_mem(json, "null", 4);
796 return;
797 }
798 }
799
800 strbuf_ensure_empty_length(json, FPCONV_G_FMT_BUFSIZE);
801 len = fpconv_g_fmt(strbuf_empty_ptr(json), num, cfg->encode_number_precision);
802 strbuf_extend_length(json, len);
803}
804
805static void json_append_object(lua_State *l, json_config_t *cfg,
806 int current_depth, strbuf_t *json)

Callers 2

json_append_objectFunction · 0.85
json_append_dataFunction · 0.85

Calls 7

lua_tonumberFunction · 0.85
json_encode_exceptionFunction · 0.85
strbuf_append_memFunction · 0.85
fpconv_g_fmtFunction · 0.85
strbuf_empty_ptrFunction · 0.85
strbuf_extend_lengthFunction · 0.85

Tested by

no test coverage detected