Skip to content

Commit

Permalink
Make structs extendable in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Apr 11, 2024
1 parent 97ce1da commit b634136
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]");
Expand Down
14 changes: 13 additions & 1 deletion pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b634136

Please sign in to comment.