Namespace qualify custom function #3203
Replies: 1 comment 1 reply
-
Hi, in the meantime a better response is available, I found something odd. Your import seems to work for The docs states that one can import values and functions, so in theory it should be able to import your value that contains an object with a function. It seems that if the value is an object, then it threats the object as the main object that contains values and functions. math.import({
foo: {
bar: 10
}
})
math.foo // currently undefined but should be {bar: 10}
math.foo.bar // currently throws an error but should be 10
math.bar // currently 10 but should be undefined. Maybe I'm misinterpreting the docs, but they state that you can import regular values, I've tried importing numbers, strings, units, arrays and objects but only numbers and strings works (I don't exactly know what regular values means) I don't think it's possible to do it in that exact way with an import but you could use a scope or a parser for that. const scope = { 'foo': { massWeight: calculateMassWeight } }
math.evaluate('foo.massWeight(10, 9.81)', scope)
function calculateMassWeight(mass, gravity) {
return mass * gravity;
} const parser = math.parser()
parser.set('foo', { massWeight: calculateMassWeight })
parser.evaluate('foo.massWeight(10, 9.81)')
function calculateMassWeight(mass, gravity) {
return mass * gravity;
} |
Beta Was this translation helpful? Give feedback.
-
I'm curious if it is possible to namespace qualify a custom function I have exposed so it's not top-level. For example, I'd like to expose the
calculateMassWeight
function under the "namespace"foo
so it is callable viafoo.calculateMassWeight
.Calling the above
math.evaluate
results in the following error.It'd be great if, instead, I get the output of actually calling the
calculateMassWeight
.Beta Was this translation helpful? Give feedback.
All reactions