From 7e4a811b2c6c6ff74af0541c13acf182aec25a2f Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Tue, 22 Nov 2022 21:34:32 +0800 Subject: [PATCH] Fix header generation for global constants --- binding_generator.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/binding_generator.py b/binding_generator.py index fd994bf8..0385f5e1 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -1458,11 +1458,18 @@ def generate_global_constants(api, output_dir): header.append(f"#ifndef {header_guard}") header.append(f"#define {header_guard}") header.append("") + header.append("#include ") + header.append("") header.append("namespace godot {") header.append("") for constant in api["global_constants"]: - header.append(f'\tconst int {escape_identifier(constant["name"])} = {constant["value"]};') + if constant["value"] == -9223372036854775808: + # INT64_MIN is an special case here. In C++ it has to be specified like this to avoid warnings + # because 9223372036854775808 can't fit inside a `long long`, so it'll be turned into a `uint64_t`. + header.append(f'\tconst int64_t {escape_identifier(constant["name"])} = -9223372036854775807 - 1;') + else: + header.append(f'\tconst int64_t {escape_identifier(constant["name"])} = {constant["value"]};') header.append("") @@ -2100,6 +2107,8 @@ def escape_identifier(id): } if id in cpp_keywords_map: return cpp_keywords_map[id] + if re.match(r"U?INT\d*_(MIN|MAX)", id): + return "_" + id return id