cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.26k stars 1.7k forks source link

Improve detection of PROTO template regeneration fields #1867

Closed stefaniapedrazzi closed 4 years ago

stefaniapedrazzi commented 4 years ago

Are there other ways to access a parameter from a Lua statement other than using the fields. prefix?

Otherwise we could maybe improve the search by including the fields. prefix in the regular expression, something like

QRegExp(QString("(^|[^a-zA-Z0-9_])fields\.%1($|[^a-zA-Z0-9_])").arg(QRegExp::escape(model->name())))))

Here is the current regular expression used to extract if a PROTO field triggers template regeneration: https://github.com/cyberbotics/webots/blob/0fe9e56f266a8855e9ab74e811f128f083307e5b/src/webots/vrml/WbProtoModel.cpp#L204

DavidMansolino commented 4 years ago

No, I don't see any other way to get the value. But we can have something like this fields.wheelFrontRight.value.fields.tireRadius.value with multiple time the fields. keyword, but this should not cause problem.

DavidMansolino commented 4 years ago

Oh, just thought that one tricky way could be to copy the dictionnary:

local newDict = fields
local parameterValue = newDict.myField.value

But none of our examples are using this, and I don't see any reason for doing this.

omichel commented 4 years ago

So, we should probably search for fields instead of fields. to be on the safe side.

DavidMansolino commented 4 years ago

I am not sure to understand how this will help to determine if the field is regenerative or not?

omichel commented 4 years ago

Sorry, forget about my comment. I was confused. The only way to handle this rare case would be to search for this kind of statement (like newDict = fields, newDict2=fields) and add all the newDict. (or whatever is found), newDict2., etc. in the search pattern in addition to fields.. But I am not sure it is worth adding that complexity to our code for such a rare use case.