Skip to content

Commit 0f53e83

Browse files
committed
Generate types in init methods
Update spec
1 parent c894494 commit 0f53e83

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rlbot-flatbuffers-py"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2021"
55
description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers"
66
repository = "https://github.com/VirxEC/rlbot-flatbuffers-py"

build.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,10 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
10861086
file_contents.push(Cow::Owned(format!(" item_type: {}Type", type_name)));
10871087
}
10881088

1089+
let mut python_types = Vec::new();
1090+
10891091
'outer: for variable_info in types {
1090-
let mut variable_name = &variable_info[0];
1092+
let mut variable_name = variable_info[0].as_str();
10911093

10921094
if variable_name == "NONE" {
10931095
continue;
@@ -1108,6 +1110,7 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
11081110

11091111
for (rust_type, python_type) in primitive_map {
11101112
if variable_type == rust_type {
1113+
python_types.push(python_type.to_string());
11111114
file_contents.push(Cow::Owned(format!(" {variable_name}: {python_type}")));
11121115
continue 'outer;
11131116
}
@@ -1118,6 +1121,8 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
11181121
.trim_start_matches("Vec<")
11191122
.trim_end_matches('>')
11201123
.trim_end_matches('T');
1124+
1125+
python_types.push(format!("list[{type_name}]"));
11211126
file_contents.push(Cow::Owned(format!(" {variable_name}: list[{type_name}]")));
11221127
} else if variable_type.starts_with("Option<") {
11231128
let type_name = variable_type
@@ -1126,24 +1131,32 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
11261131
.trim_end_matches('>')
11271132
.trim_end_matches('T');
11281133

1129-
if type_name == "bool" {
1130-
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[bool]")));
1134+
let python_type = if type_name == "bool" {
1135+
"bool"
11311136
} else if type_name == "i32" || type_name == "u32" {
1132-
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[int]")));
1137+
"int"
11331138
} else if type_name == "f32" {
1134-
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[float]")));
1139+
"float"
11351140
} else if type_name == "String" {
1136-
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[str]")));
1141+
"str"
11371142
} else {
1138-
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[{type_name}]")));
1139-
}
1143+
type_name
1144+
};
1145+
1146+
python_types.push(format!("Optional[{python_type}]"));
1147+
file_contents.push(Cow::Owned(format!(" {variable_name}: Optional[{python_type}]")));
11401148
} else if variable_type.starts_with("Box<") && variable_type.ends_with("T>") {
11411149
let type_name = variable_type.trim_start_matches("Box<").trim_end_matches("T>");
1150+
1151+
python_types.push(type_name.to_string());
11421152
file_contents.push(Cow::Owned(format!(" {variable_name}: {type_name}")));
11431153
} else if variable_type.ends_with('T') {
11441154
let type_name = variable_type.trim_end_matches('T');
1155+
1156+
python_types.push(type_name.to_string());
11451157
file_contents.push(Cow::Owned(format!(" {variable_name}: {type_name}")));
11461158
} else {
1159+
python_types.push(variable_type.clone());
11471160
file_contents.push(Cow::Owned(format!(" {variable_name}: {variable_type}")));
11481161
}
11491162
}
@@ -1156,6 +1169,7 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
11561169
file_contents.push(Cow::Borrowed(" def __init__("));
11571170
file_contents.push(Cow::Borrowed(" self,"));
11581171

1172+
let mut i = 0;
11591173
for variable_info in types {
11601174
if &variable_info[0] == "NONE" {
11611175
continue;
@@ -1187,7 +1201,10 @@ fn pyi_generator(type_data: &[(String, String, Vec<Vec<String>>)]) -> io::Result
11871201
}
11881202
};
11891203

1190-
file_contents.push(Cow::Owned(format!(" {variable_name}={default_value},")));
1204+
let python_type = &python_types[i];
1205+
file_contents.push(Cow::Owned(format!(" {variable_name}: {python_type}={default_value},")));
1206+
1207+
i += 1;
11911208
}
11921209

11931210
file_contents.push(Cow::Borrowed(" ): ..."));

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pynamedmodule! {
4848
GameStateType,
4949
GameSpeedOption,
5050
ScoreInfo,
51-
BotSpawnIndex,
5251
MessagePacket,
5352
DemolishOption,
5453
Vector3Partial,

0 commit comments

Comments
 (0)