Duet3D / RepRapFirmware

OO C++ RepRap Firmware
GNU General Public License v3.0
925 stars 532 forks source link

Storing and dereferencing object references in variables #961

Open Mogatek opened 4 months ago

Mogatek commented 4 months ago

Is your feature request related to a problem? Please describe.

As per this forum post, I tried to store a ref to partial sub-tree of the object model in a variable for easier access and more readable code.

var tool = 0
var toolHeater = heat.heaters[tools[var.tool].heaters[0]]

;--- Accessing the "current" member. As of now, this is not possible:
echo var.toolHeater.current

;--- Expected behaviour would be the equivalent to:
echo heat.heaters[tools[var.tool].heaters[0]].current

Describe the solution you propose.

It would be a great addition to the syntax if we could somehow store object references in variables, then later dereference them as required, accessing the original part of the object model.

Describe alternatives you've considered

As of now, @dc42 has confirmed that this is not possible. The only way is to use a whole path to the endpoint at every place where it is required.

Provide any additional context or information.

No response

w1ebr commented 4 months ago

What about using string substitution (similar to using a preprocessor variable) vs referencing and dereferencing? On Feb 29, 2024, at 11:10 AM, Gabriella M. @.***> wrote: Is your feature request related to a problem? Please describe. As per this forum post, I tried to store a ref to partial sub-tree of the object model in a variable for easier access and more readable code. var tool = 0 var toolHeater = heat.heaters[tools[var.tool].heaters[0]]

;--- Accessing the "current" member. As of now, this is not possible: echo var.toolHeater.current

;--- Expected behaviour would be the equivalent to: echo heat.heaters[tools[var.tool].heaters[0]].current

Describe the solution you propose. It would be a great addition to the syntax if we could somehow store object references in variables, then later dereference them as required, accessing the original part of the object model. Describe alternatives you've considered As of now, @dc42 has confirmed that this is not possible. The only way is to use a whole path to the endpoint at every place where it is required. Provide any additional context or information. No response

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

Mogatek commented 4 months ago

What about using string substitution (similar to using a preprocessor variable) vs referencing and dereferencing?

Hmm, could be a possible workaround, but is that possible? I just read the documentation twice again, but I did not find anything that evaluates a string's contents as a command.

dc42 commented 4 months ago

Correct, there is no facility to interpret a string expression as a command.