Skip to content

Commit

Permalink
Add HAL_Value to remove stubgen complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Nov 27, 2023
1 parent 375e046 commit b728888
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions subprojects/robotpy-hal/hal/src/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@ RPYBUILD_PYBIND11_MODULE(m) {
.value("INT", HAL_Type::HAL_INT)
.value("LONG", HAL_Type::HAL_LONG);

// Add this manually because it would be annoying to do otherwise
py::class_<HAL_Value>(m, "Value")
.def_readonly("type", &HAL_Value::type)
.def_property_readonly("value",
[](const HAL_Value &self) -> py::object {
switch (self.type) {
case HAL_BOOLEAN:
return py::bool_(self.data.v_boolean);
case HAL_DOUBLE:
return py::float_(self.data.v_double);
case HAL_ENUM:
return py::int_(self.data.v_enum);
case HAL_INT:
return py::int_(self.data.v_int);
case HAL_LONG:
return py::int_(self.data.v_long);
default:
return py::none();
}
}
)
.def("__repr__", [](const HAL_Value &self) -> py::str {
switch (self.type) {
case HAL_BOOLEAN:
return "<Value type=bool value=" + std::to_string(self.data.v_boolean) + ">";
case HAL_DOUBLE:
return "<Value type=double value=" + std::to_string(self.data.v_double) + ">";
case HAL_ENUM:
return "<Value type=enum value=" + std::to_string(self.data.v_enum) + ">";
case HAL_INT:
return "<Value type=int value=" + std::to_string(self.data.v_int) + ">";
case HAL_LONG:
return "<Value type=long value=" + std::to_string(self.data.v_long) + ">";
default:
return "<Value type=invalid>";
}
});

initWrapper(m);

#ifdef __FRC_ROBORIO__
Expand Down

0 comments on commit b728888

Please sign in to comment.