Skip to content

Commit ca346fe

Browse files
committed
use std::array to implement fixed arrays
`std::array` is byte-equivalent to a C style array, so this will always work with DF's structures, but using `std::array` gives us a lot of coding convenience on our side as `std::array` has much more reasonable semantics than a C-style array these changes require a coordinated change in the dfhack repository
1 parent 4955a64 commit ca346fe

3 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎StructFields.pm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,9 @@ sub get_struct_field_type($;%) {
340340
$prefix = get_container_item_type($tag, -weak => 1, -void => 'void')."*";
341341
} elsif ($meta eq 'static-array') {
342342
($prefix, $suffix) = get_container_item_type($tag);
343+
header_ref("array");
343344
my $count = get_container_count($tag);
344-
$suffix = "[$count]".$suffix;
345+
$prefix = "std::array<$prefix,$count>";
345346
} elsif ($meta eq 'primitive') {
346347
local $_ = $tag;
347348
my $handler = $custom_primitive_handlers{$subtype} or die "Invalid primitive: $subtype\n";

‎changelog.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Template for new versions:
1919
# Future
2020

2121
## Structures
22+
- changed codegen to use ``std::array`` for fixed-length arrays instead of C-style arrays
2223

2324
# 53.15-r1
2425

‎codegen.pl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ BEGIN
154154
emit "INIT_GLOBAL_FUNCTION_PREFIX";
155155

156156
for my $item (@items) {
157-
emit "INIT_GLOBAL_FUNCTION_ITEM(", $item->[0], ', ', $item->[1], ");";
157+
emit "INIT_GLOBAL_FUNCTION_ITEM(", $item->[1], ', ', $item->[0], ");";
158158
}
159159
} "void InitGlobals() ";
160160
} "namespace global ";

0 commit comments

Comments
 (0)