Bitfocus Companion enables the reasonably priced Elgato Streamdeck and other controllers to be a professional shotbox surface for an increasing amount of different presentation switchers, video playback software and broadcast equipment.
This provides a bunch of improvements to expressions.
The most visible difference is that expression input fields are now displayed as multiline:
Expression input fields will now validate their expression in the ui, and will show as red when it failed to parse (execution is not tested)
Additionally, to make this more friendly, it includes some new syntax:
Comments are now allowed. Same as javascript, both // and /* ... */
Expressions can be multiline. Arbitrary line breaks are allowed, which allows for better formatting.
return is a supported operation. Not exactly useful right now, but this can be nice to make an expression more readable in what the output value is
It is possible to define intermediary variable inside an expression. Something such as a = 1 ; return a + 2 is now valid and will compute a value of 3. The values of these are not persisted outside of the execution the expression.
The 'full' range of assignment operators is functional, including things like +=, and ++
Combine all of these, and you can now break up long complex expressions into multiple stages, with comments and intermediary variables.
The value of the last statement is taken as the output. eg 10 20 30 is 3 statements, and the result will be 30.
The statement parsing isn't perfect js, the parser is allowing multiple statements on a single line separated by only a space. I worry that this could result in the parsing being more brittle, but I'm not sure if we should be worried about that.
Maybe next could be support for full if statements, or loops, but not as part of this PR.
This provides a bunch of improvements to expressions.
The most visible difference is that expression input fields are now displayed as multiline:![image](https://github.com/bitfocus/companion/assets/1327476/621a71dc-585e-48fd-b5de-acda6632815c)
Expression input fields will now validate their expression in the ui, and will show as red when it failed to parse (execution is not tested)
Additionally, to make this more friendly, it includes some new syntax:
//
and/* ... */
return
is a supported operation. Not exactly useful right now, but this can be nice to make an expression more readable in what the output value isa = 1 ; return a + 2
is now valid and will compute a value of3
. The values of these are not persisted outside of the execution the expression.+=
, and++
Combine all of these, and you can now break up long complex expressions into multiple stages, with comments and intermediary variables. The value of the last statement is taken as the output. eg
10 20 30
is 3 statements, and the result will be30
.The statement parsing isn't perfect js, the parser is allowing multiple statements on a single line separated by only a space. I worry that this could result in the parsing being more brittle, but I'm not sure if we should be worried about that.
Maybe next could be support for full if statements, or loops, but not as part of this PR.