Compare commits

...

2 Commits

Author SHA1 Message Date
Haoyu Qiu 3eb891173f
Merge 7e4a811b2c into 588d869a3b 2023-11-24 22:31:19 +08:00
Haoyu Qiu 7e4a811b2c Fix header generation for global constants 2022-11-22 21:34:32 +08:00
1 changed files with 10 additions and 1 deletions

View File

@ -1686,11 +1686,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 <cstdint>")
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("")
@ -2405,6 +2412,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