Add mjs_getPluginAttributes.

PiperOrigin-RevId: 752691116
Change-Id: Ib503a99f8d10661b8bf92410ccf471420f924986
This commit is contained in:
Alessio Quaglino
2025-04-29 05:18:17 -07:00
committed by Copybara-Service
parent 2545ec5383
commit 3e9d130092
8 changed files with 52 additions and 3 deletions
+16
View File
@@ -10298,6 +10298,22 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc='Get double array contents and optionally its size.',
)),
('mjs_getPluginAttributes',
FunctionDecl(
name='mjs_getPluginAttributes',
return_type=PointerType(
inner_type=ValueType(name='void', is_const=True),
),
parameters=(
FunctionParameterDecl(
name='plugin',
type=PointerType(
inner_type=ValueType(name='mjsPlugin', is_const=True),
),
),
),
doc='Get plugin attributes.',
)),
('mjs_setDefault',
FunctionDecl(
name='mjs_setDefault',
+11 -3
View File
@@ -1034,8 +1034,15 @@ PYBIND11_MODULE(_specs, m) {
[](raw::MjsPlugin& self) { mjs_delete(self.element); });
mjsPlugin.def_property(
"config",
[](raw::MjsPlugin& self) -> void {
throw pybind11::value_error("Reading plugin config is not supported.");
[](raw::MjsPlugin& self) -> py::dict {
const std::map<std::string, std::string, std::less<>>* config_attribs =
static_cast<const std::map<std::string, std::string, std::less<>>*>(
mjs_getPluginAttributes(&self));
py::dict config;
for (const auto& [key, value] : *config_attribs) {
config[py::str(key)] = value;
}
return config;
},
[](raw::MjsPlugin& self, py::dict& config) {
std::map<std::string, std::string, std::less<>> config_attribs;
@@ -1047,7 +1054,8 @@ PYBIND11_MODULE(_specs, m) {
config_attribs[key_str] = value.cast<std::string>();
}
mjs_setPluginAttributes(&self, &config_attribs);
});
},
py::return_value_policy::reference_internal);
// ============================= MJVISUAL ====================================
mjVisual.def_property(
"global_",
+1
View File
@@ -844,6 +844,7 @@ class SpecsTest(absltest.TestCase):
info='info'
)
plugin.config = {'twist': '10', 'bend': '1'}
self.assertEqual(plugin.config, {'twist': '10', 'bend': '1'})
body = spec.worldbody.add_body()
body.plugin = plugin