Skip to content

Commit

Permalink
Expose MjSpec raw pointer via _address
Browse files Browse the repository at this point in the history
  • Loading branch information
jjyyxx committed Feb 26, 2025
1 parent d1d6192 commit 2039629
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/mujoco/specs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ PYBIND11_MODULE(_specs, m) {
mjSpec.def("copy", [](const MjSpec& self) -> MjSpec {
return MjSpec(self);
});
mjSpec.def_property_readonly("_address", [](const MjSpec& self) {
return reinterpret_cast<uintptr_t>(self.ptr);
});
mjSpec.def_property(
"copy_during_attach",
[](MjSpec& self) {
Expand Down
10 changes: 10 additions & 0 deletions python/mujoco/specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,5 +1159,15 @@ def test_incorrect_hfield_size(self):
):
model_spec.compile()

def test_address(self):
spec1 = mujoco.MjSpec()
spec2 = mujoco.MjSpec()
spec3 = spec1.copy()

self.assertGreater(spec1._address, 0)
self.assertGreater(spec2._address, 0)
self.assertGreater(spec3._address, 0)
self.assertLen({spec1._address, spec2._address, spec3._address}, 3)

if __name__ == '__main__':
absltest.main()

0 comments on commit 2039629

Please sign in to comment.