From b63413614585b9d10d8bdf6131a62907adccda5b Mon Sep 17 00:00:00 2001 From: VirxEC Date: Thu, 11 Apr 2024 12:58:27 -0400 Subject: [PATCH] Make structs extendable in Python --- Cargo.lock | 2 +- Cargo.toml | 2 +- build.rs | 2 +- pytest.py | 14 +++++++++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5103b70..743cb6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,7 +322,7 @@ dependencies = [ [[package]] name = "rlbot-flatbuffers-py" -version = "0.3.1" +version = "0.3.2" dependencies = [ "flatbuffers", "get-size", diff --git a/Cargo.toml b/Cargo.toml index 2cb00ab..51ad353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rlbot-flatbuffers-py" -version = "0.3.1" +version = "0.3.2" edition = "2021" description = "A Python module implemented in Rust for serializing and deserializing RLBot's flatbuffers" repository = "https://github.com/VirxEC/rlbot-flatbuffers-py" diff --git a/build.rs b/build.rs index 11bf270..ee2d8b2 100644 --- a/build.rs +++ b/build.rs @@ -253,7 +253,7 @@ impl PythonBindGenerator { } fn generate_struct_definition(&mut self) { - self.write_str("#[pyclass(module = \"rlbot_flatbuffers\", get_all, set_all)]"); + self.write_str("#[pyclass(module = \"rlbot_flatbuffers\", subclass, get_all, set_all)]"); if self.types.is_empty() { self.write_str("#[derive(Debug, Default, Clone)]"); diff --git a/pytest.py b/pytest.py index 12ab1b8..4c2991d 100644 --- a/pytest.py +++ b/pytest.py @@ -2,7 +2,17 @@ from rlbot_flatbuffers import * + +class MyVector(Vector3): + def __add__(self, other): + return MyVector(self.x + other.x, self.y + other.y, self.z + other.z) + + if __name__ == "__main__": + vec1 = MyVector(1, 2, 3) + vec2 = Vector3(4, 5, 6) + print(vec1 + vec2) + ready_message = ReadyMessage(True, wants_game_messages=True) print(repr(ready_message)) print(ready_message) @@ -51,7 +61,9 @@ desired_game_state = DesiredGameState( DesiredBallState(DesiredPhysics()), car_states=[DesiredCarState(boost_amount=100)], - game_info_state=DesiredGameInfoState(game_speed=1, world_gravity_z=-650, end_match=True), + game_info_state=DesiredGameInfoState( + game_speed=1, world_gravity_z=-650, end_match=True + ), console_commands=[ConsoleCommand("freeze")], ) total_make_time += time_ns() - start