Return 0 on success from mjs_activatePlugin instead of using mju_error.
PiperOrigin-RevId: 684102823 Change-Id: I86b7702094ae886539e1dfb6294381952d507bc1
This commit is contained in:
committed by
Copybara-Service
parent
5dcc31a6aa
commit
a26ba2012e
@@ -1516,7 +1516,7 @@ mjs_activatePlugin
|
|||||||
|
|
||||||
.. mujoco-include:: mjs_activatePlugin
|
.. mujoco-include:: mjs_activatePlugin
|
||||||
|
|
||||||
Activate plugin.
|
Activate plugin. Returns 0 on success.
|
||||||
|
|
||||||
.. _Errorandmemory:
|
.. _Errorandmemory:
|
||||||
|
|
||||||
|
|||||||
@@ -3178,7 +3178,7 @@ int mj_setLengthRange(mjModel* m, mjData* d, int index,
|
|||||||
mjSpec* mj_makeSpec(void);
|
mjSpec* mj_makeSpec(void);
|
||||||
mjSpec* mj_copySpec(const mjSpec* s);
|
mjSpec* mj_copySpec(const mjSpec* s);
|
||||||
void mj_deleteSpec(mjSpec* s);
|
void mj_deleteSpec(mjSpec* s);
|
||||||
void mjs_activatePlugin(mjSpec* s, const char* name);
|
int mjs_activatePlugin(mjSpec* s, const char* name);
|
||||||
void mj_printFormattedModel(const mjModel* m, const char* filename, const char* float_format);
|
void mj_printFormattedModel(const mjModel* m, const char* filename, const char* float_format);
|
||||||
void mj_printModel(const mjModel* m, const char* filename);
|
void mj_printModel(const mjModel* m, const char* filename);
|
||||||
void mj_printFormattedData(const mjModel* m, mjData* d, const char* filename,
|
void mj_printFormattedData(const mjModel* m, mjData* d, const char* filename,
|
||||||
|
|||||||
@@ -241,8 +241,8 @@ MJAPI mjSpec* mj_copySpec(const mjSpec* s);
|
|||||||
// Free memory allocation in mjSpec.
|
// Free memory allocation in mjSpec.
|
||||||
MJAPI void mj_deleteSpec(mjSpec* s);
|
MJAPI void mj_deleteSpec(mjSpec* s);
|
||||||
|
|
||||||
// Activate plugin.
|
// Activate plugin. Returns 0 on success.
|
||||||
MJAPI void mjs_activatePlugin(mjSpec* s, const char* name);
|
MJAPI int mjs_activatePlugin(mjSpec* s, const char* name);
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------- Printing ------------------------------------------------------
|
//---------------------------------- Printing ------------------------------------------------------
|
||||||
|
|||||||
@@ -1048,7 +1048,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
|||||||
('mjs_activatePlugin',
|
('mjs_activatePlugin',
|
||||||
FunctionDecl(
|
FunctionDecl(
|
||||||
name='mjs_activatePlugin',
|
name='mjs_activatePlugin',
|
||||||
return_type=ValueType(name='void'),
|
return_type=ValueType(name='int'),
|
||||||
parameters=(
|
parameters=(
|
||||||
FunctionParameterDecl(
|
FunctionParameterDecl(
|
||||||
name='s',
|
name='s',
|
||||||
@@ -1063,7 +1063,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
doc='Activate plugin.',
|
doc='Activate plugin. Returns 0 on success.',
|
||||||
)),
|
)),
|
||||||
('mj_printFormattedModel',
|
('mj_printFormattedModel',
|
||||||
FunctionDecl(
|
FunctionDecl(
|
||||||
|
|||||||
@@ -206,14 +206,15 @@ void mjs_addSpec(mjSpec* s, mjSpec* child) {
|
|||||||
|
|
||||||
|
|
||||||
// activate plugin
|
// activate plugin
|
||||||
void mjs_activatePlugin(mjSpec* s, const char* name) {
|
int mjs_activatePlugin(mjSpec* s, const char* name) {
|
||||||
int plugin_slot = -1;
|
int plugin_slot = -1;
|
||||||
const mjpPlugin* plugin = mjp_getPlugin(name, &plugin_slot);
|
const mjpPlugin* plugin = mjp_getPlugin(name, &plugin_slot);
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
mju_error("unknown plugin '%s'", name);
|
return -1;
|
||||||
}
|
}
|
||||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||||
model->ActivatePlugin(plugin, plugin_slot);
|
model->ActivatePlugin(plugin, plugin_slot);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -63,8 +63,8 @@ MJAPI void mj_deleteSpec(mjSpec* s);
|
|||||||
// Add spec (model asset) to spec.
|
// Add spec (model asset) to spec.
|
||||||
MJAPI void mjs_addSpec(mjSpec* s, mjSpec* child);
|
MJAPI void mjs_addSpec(mjSpec* s, mjSpec* child);
|
||||||
|
|
||||||
// Activate plugin.
|
// Activate plugin, return 0 on success.
|
||||||
MJAPI void mjs_activatePlugin(mjSpec* s, const char* name);
|
MJAPI int mjs_activatePlugin(mjSpec* s, const char* name);
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------- Attachment ----------------------------------------------------
|
//---------------------------------- Attachment ----------------------------------------------------
|
||||||
|
|||||||
@@ -2890,7 +2890,9 @@ void mjXReader::Extension(XMLElement* section) {
|
|||||||
if (name == "plugin") {
|
if (name == "plugin") {
|
||||||
string plugin_name;
|
string plugin_name;
|
||||||
ReadAttrTxt(elem, "plugin", plugin_name, /* required = */ true);
|
ReadAttrTxt(elem, "plugin", plugin_name, /* required = */ true);
|
||||||
mjs_activatePlugin(spec, plugin_name.c_str());
|
if (mjs_activatePlugin(spec, plugin_name.c_str())) {
|
||||||
|
throw mjXError(elem, "plugin %s not found", plugin_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
XMLElement* child = FirstChildElement(elem);
|
XMLElement* child = FirstChildElement(elem);
|
||||||
while (child) {
|
while (child) {
|
||||||
|
|||||||
Reference in New Issue
Block a user