Added resolve function to allow users to force a calculation to reduce

This commit is contained in:
Stefan Zermatten
2022-02-23 12:58:12 +02:00
parent 52453b46e9
commit 5b6bff91a4
2 changed files with 21 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
import resolve from '/imports/parser/resolve.js'
export default {
'abs': {
comment: 'Returns the absolute value of a number',
@@ -108,6 +110,18 @@ export default {
}
return arrayNode.values.length;
}
},
'resolve': {
comment: 'Forces the given calcultion to resolve into a number',
examples: [
{input: 'resolve(someUndefinedVariable + 3 + 4)', result: '7'},
{input: 'resolve(3d6)', result: '2'},
],
arguments: ['parseNode'],
fn: function resolveFn(node){
let {result} = resolve('reduce', node, this.scope, this.context);
return result;
}
}
}