Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FeatureRequest]: Add a means to check the type of a variable #865

Open
dc42 opened this issue Jun 10, 2023 · 0 comments
Open

[FeatureRequest]: Add a means to check the type of a variable #865

dc42 opened this issue Jun 10, 2023 · 0 comments
Assignees
Labels
enhancement Additional functionality, performance or other feature request

Comments

@dc42
Copy link
Collaborator

dc42 commented Jun 10, 2023

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

It would be good to be able to validate the parameters to a macro file at its start. See https://forum.duet3d.com/topic/32467/q-how-to-check-the-type-of-a-variable.

Describe the solution you propose.

[DC] Some possibilities:

  1. Introduce a "typeof" operator along with type names. Then we could use expressions such as:

if typeof(param.D) = typeof(int)

  1. To avoid introducing type names, introduce a separate operator for most types, e.g.:

if isInteger(param.D)]

We wouldn't need a isString function because any parameter can be converted to a string, but we would need functions to test most or all other types.

  1. Introduce a typeof operator as in Added new "I" parameter to M106 #1 but also introduce named constants for each type, e.g.:

if typeof(param.D) = typeInt

  1. Similar to Added new "I" parameter to M106 #1 or FTP and partial Telnet support #3 but allow conversions, e.g.:

if canConvert(param.D, typeInt)

This approach may be more useful because it will avoid the need to test for int and float separately.

@dc42 dc42 added the enhancement Additional functionality, performance or other feature request label Jun 10, 2023
@dc42 dc42 assigned x0rtrunks and dc42 and unassigned x0rtrunks Jun 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additional functionality, performance or other feature request
Projects
None yet
Development

No branches or pull requests

2 participants