diff --git a/sources/iron.h b/sources/iron.h index abeab86..6d17e99 100644 --- a/sources/iron.h +++ b/sources/iron.h @@ -826,8 +826,13 @@ f32 math_acos(f32 x) { return acosf(x); } f32 math_exp(f32 x) { return expf(x); } f32 math_fmod(f32 x, f32 y) { return fmod(x, y); } +#ifdef _WIN32 +i32 parse_int(const char *s) { return _strtoi64(s, NULL, 10); } +i32 parse_int_hex(const char *s) { return _strtoi64(s, NULL, 16); } +#else i32 parse_int(const char *s) { return strtol(s, NULL, 10); } i32 parse_int_hex(const char *s) { return strtol(s, NULL, 16); } +#endif f32 parse_float(const char *s) { return strtof(s, NULL); } i32 color_from_floats(f32 r, f32 g, f32 b, f32 a) { diff --git a/sources/iron_json.c b/sources/iron_json.c index 5dde98a..5433c28 100644 --- a/sources/iron_json.c +++ b/sources/iron_json.c @@ -28,6 +28,9 @@ static void store_u8(uint8_t u8) { } static void store_i32(int32_t i32) { + // TODO: signed overflow is UB + // if (i32 > INT32_MAX) + // i32 = (int32_t)(i32 - INT32_MAX - 1) - INT32_MAX - 1; wi += pad(wi, 4); *(int32_t *)(decoded + wi) = i32; wi += 4; @@ -149,7 +152,11 @@ static void token_write() { else { has_dot(source + t.start, t.end - t.start) ? store_f32(strtof(source + t.start, NULL)) : + #ifdef _WIN32 + store_i32(_strtoi64(source + t.start, NULL, 10)); + #else store_i32(strtol(source + t.start, NULL, 10)); + #endif } } else if (t.type == JSMN_ARRAY) { diff --git a/sources/iron_ui_ext.c b/sources/iron_ui_ext.c index 697f9fd..b26ebfc 100644 --- a/sources/iron_ui_ext.c +++ b/sources/iron_ui_ext.c @@ -425,7 +425,11 @@ int ui_color_wheel(ui_handle_t *handle, bool alpha, float w, float h, bool color hex_code[0] = 'f'; hex_code[1] = 'f'; } + #ifdef _WIN32 + handle->color = _strtoi64(hex_code, NULL, 16); + #else handle->color = strtol(hex_code, NULL, 16); + #endif } if (h0->changed || h1->changed || h2->changed) { handle->changed = current->changed = true; diff --git a/sources/ts/ui.ts b/sources/ts/ui.ts index 8e51ce1..e331fd2 100644 --- a/sources/ts/ui.ts +++ b/sources/ts/ui.ts @@ -354,7 +354,7 @@ declare type ui_options_t = { }; declare type ui_coloring_t = { - color?: i32; + color?: u32; start?: string[]; end?: string; separated?: bool; @@ -362,7 +362,7 @@ declare type ui_coloring_t = { declare type ui_text_coloring_t = { colorings?: ui_coloring_t[]; - default_color?: i32; + default_color?: u32; }; declare type ui_canvas_control_t = { @@ -384,7 +384,7 @@ declare type ui_node_t = { type?: string; x?: f32; y?: f32; - color?: i32; + color?: u32; inputs?: ui_node_socket_t[]; outputs?: ui_node_socket_t[]; buttons?: ui_node_button_t[]; @@ -396,7 +396,7 @@ declare type ui_node_socket_t = { node_id?: i32; name?: string; type?: string; - color?: i32; + color?: u32; default_value?: f32_array_t; min?: f32; max?: f32; diff --git a/tools/amake/iron.h b/tools/amake/iron.h index 1a47c80..6644079 100644 --- a/tools/amake/iron.h +++ b/tools/amake/iron.h @@ -62,6 +62,11 @@ f32 math_acos(f32 x) { return acosf(x); } f32 math_exp(f32 x) { return expf(x); } f32 math_fmod(f32 x, f32 y) { return fmod(x, y); } +#ifdef _WIN32 +i32 parse_int(const char *s) { return _strtoi64(s, NULL, 10); } +i32 parse_int_hex(const char *s) { return _strtoi64(s, NULL, 16); } +#else i32 parse_int(const char *s) { return strtol(s, NULL, 10); } i32 parse_int_hex(const char *s) { return strtol(s, NULL, 16); } +#endif f32 parse_float(const char *s) { return strtof(s, NULL); }