Hey all,I've wrapped math.js's eval function as a javascript macro. http://www.mklauber.com/mathjs.html For those of you not familiar with math.js and eval, the short of it is that eval is able to intelligently evaluate mathematical expressions while not exposing th typical security issues inherent in eval.
Hey all,I've wrapped math.js's eval function as a javascript macro. http://www.mklauber.com/mathjs.html For those of you not familiar with math.js and eval, the short of it is that eval is able to intelligently evaluate mathematical expressions while not exposing th typical security issues inherent in eval.
In addition to just being able to evaluate standard expressions, I've added support for TextReferences among the code, so now you can store data in fields or data tiddlers and right expressions based on that data. However, one issue I've run into with this is listening for and responding to changes on other tiddlers. If anyone has a quick suggestion on how to handle that, I would be appreciative.Matt Lauber
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f7b4055e-fb25-4556-8cee-fc8dc834d8d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
My reason for reinventing this as a widget instead of as a macro was that macros don't respond to changes in the virtual Dom, nor can they listen for toddler changed events. This means if you reference a field on another tiddler, you won't update if that value changes.
<$tiddler tiddler="some tiddler">
<<calc foo>>
</$tiddler>
I can certainly include the marco with limitations. But the issue is worse than you think, I feel. For each separate TextReference in the text of the macro, you would need an additional <$tiddler> block.
<$calc id="result" display:"none">{{Text!!Reference}} / 2</$calc>
<<= result>>
<<= result int>>
<<= result float>>Hi Matthew,How about:
<$calc id="result" display:"none">{{Text!!Reference}} / 2</$calc>
<<int result>>
<<float result>>
<<string result>>
<<bool result>>?Whereas...
- int => parses innerHTML as integer
- float => parses innerHTML as float
- string => fetches innerHTML as string
- bool => parses innerHTML as boolean
... and returns the value as a string, obviously.Best wishes,— tb
<<= some-reference>><$hide id="some-reference"><$calc>1 + 1</$calc></$hide>
<<= #some-reference>><$hide class="some-reference"><$calc>1 + 1</$calc></$hide>
<$hide class="some-reference">1</$hide>
<<= .some-reference>>
<p id="some-reference" class="tc-hide"><$calc>1 + 1.1</$calc></p>
<<= #some-reference int>><p class="some-reference tc-hide"><$calc>1 + 1</$calc></p>
<p class="some-reference tc-hide">1.1</p>
<<= .some-reference float>><$set name="myVariable" value="Some text"> <$text text=<<myVariable>>/> </$set>
i.e.the setting (writer) widget needs to be the parent of the reading widgets.
so you could do:
</$calc>
all the best
BJ
I think variables have to be used like this;
<p class="my-var tc-hide"><$calc>{{Text!!Reference}} + {{Another##reference}}</$calc></p>
<<= my-var>>
Hey all,
I've wrapped math.js's eval function as a javascript macro. http://www.mklauber.com/mathjs.html For those of you not familiar with math.js and eval, the short of it is that eval is able to intelligently evaluate mathematical expressions while not exposing th typical security issues inherent in eval.
In addition to just being able to evaluate standard expressions, I've added support for TextReferences among the code, so now you can store data in fields or data tiddlers and right expressions based on that data. However, one issue I've run into with this is listening for and responding to changes on other tiddlers. If anyone has a quick suggestion on how to handle that, I would be appreciative.
Matt Lauber
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/902e6d17-5c0a-46e4-9fd7-ee75fa65f110%40googlegroups.com.
This is more what I was picturing.
<$calc variable="some-variable">1 + 1</$calc>
<< some-variable >>
<p id="some-reference" class="tc-hide"><$calc>1 + 1.1</$calc></p>
<$some-widget attr=<<= #some-reference int>>/>
<$vars bar=<<calc "{text!!reference} - <baz>">> frotz=<<calc "{!!gronk}^3/4">>>
<$some-widget foo=<<bar>> mumble=<<frotz>>/>
</$vars>
One quick update. I've released version 1.1.0 which includes a new parameter "silence" which silences the parse error text. This is for use with forms where having the parse error text visible while changing the input in not desired. Still available at http://mklauber.github.io/tiddly-mathjs/ You can get the older version at http://mklauber.github.io/tiddly-mathjs/1.0.0.html
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d6ce29ff-bd69-469e-b799-17015b766558%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/35791211-c01f-4630-ad74-eb5536d8abe6%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/4985aabe-9c3b-4668-9d1b-58246f718085%40googlegroups.com.



Hey all,I've wrapped math.js's eval function as a javascript macro. http://mklauber.github.io/tiddly-mathjs/ For those of you not familiar with math.js and eval, the short of it is that eval is able to intelligently evaluate mathematical expressions while not exposing th typical security issues inherent in eval.