I want my playsound macro to work both with constant names and expressions, like
<<set $wav=".wav";i=2>>
<<playsound "fall"+$i+$wav>>
In the handler
handler: function (a, b, c, d) {
var s = (d.fullArgs());
this.domacro(b,s);
}
domacro is the function that does the main job:
domacro: function(b, s) {
if (s) {
alert(s);//for debugging
s=eval(Wikifier.parse(s));
//...et cetera...
Trying:
<<playsound "fall2.wav">>
s becomes "fall2.wav", all works.
<<playsound "fall"+$i+$wav>>
s becomes state.history[0].variables.wav == null && (state.history[0].variables.wav = 0);state.history[0].variables.i == null && (state.history[0].variables.i = 0);"fall"+state.history[0].variables.i+state.history[0].variables.wav
(yes,I copy-pasted this string exactly as it was displayed by the alert box)
So far so good, unless I need a second parameter:
<<loopsound "fall"+$i+$wav $times>>
s becomes state.history[0].variables.times == null && (state.history[0].variables.times = 0);state.history[0].variables.wav == null && (state.history[0].variables.wav = 0);state.history[0].variables.i == null && (state.history[0].variables.i = 0);"fall"+state.history[0].variables.i+state.history[0].variables.wav state.history[0].variables.times
So, the problem is: I need to split s to send each parameter to eval(Wikifier.parse()), but the parameters codes are separated by spaces, and the same spaces are used inside their codes. There is no way to understand where one parameter ends and the next begins!
I can replace " == " with "==" and " = " with "=" and " && " with "&&", but I'm not sure if any more complex expressions can produce more kinds of spaces. Any ideas?
Comments
c.length will not do the job, as is case of an expression it returns its parts as different parameters: fall,+$i+$wav,$times
3
You can use open and close parenthesis to indicate that a parameter is an expression like so