To the topic. It's unfinished. No floating-point functions like sin, cos etc, but it's usable for testing.
ToDo:
1. push / pop
2. arrays
3. functions:
a) floating point
b) type conversions
c) user defined
Copy math.zip\plugin\math.dll to your plugins folder and see math.zip\math.nsi as example.
here comes math.txt:
C-like style scripting (operators at least).
Tip: plugin watches the case of the letters.
How to use it? Simple:
Strcpy $0 "Brainsucker"
Math::Script "a = 'Math'; B = 'Script'; r0 += ' wants to use ' + a + '::' + b +'!'"
DetailPrint "$0"
That string will fill r0 with some shit.
Here are some other samples:
10! (factorial, r0 will contain '10! = 362880'):
r0 = '10! = ' + (1*2*3*4*5*6*7*8*9)
the same:
a = b = 1; {++a <= 10, b = b*a}; r0 = (a-1) + '! = ' + b
Some floating point:
Strcpy $R0 "1e1"
Math::Script "pi = 3.14159; R1 = 2*pi*R0; r0 = 'Length of circle with radius ' + R0 + ' is equal to ' + R1 + '.'"
Detailprint "$0"
Ok. Variables.
NSIS: r0-r9 -> $0-$9. R0-R9 -> $R0-$R9.
Also CMDLINE, INSTDIR, OUTDIR, LANG, EXEDIR.
User definable: name starting from character, up to 28 letters long.
Supported types: int (in fact that is __int64), float (double in fact),
string.
Int: just numbers, may include sign.
Float: -123.456, 123.456e-78, 123e-45
String: something in quotes ("", '', ``).
Operators (some binary, some unary):
>>= <<= -= += /= *= |= &= ^= %= -- ++ >> << && || <= =< >= => != ==
-> <- = + - * / % < > & | ^ ~ !
Only some are applicable to float (logic & arithmetic) and string (+ and logic)
of course.
Script is set of expressions (mathematical in general) delimeted with ';'.
Processing is not mathematicaly right (2+2*2 will give 8, not 6), so use round
brakes (for ex: 2+(2*2) ).
Flow control:
if-then-else like: [if-expression, then-expr, else-expr]
example:
[a==0, b=1; c=2, b *= (--c); c/=10]
C eq:
if (a==0) { b=1; c=2;} else { b*=(c++);c-=10; }
while (expr) do; like {expr, do}
example:
{(c<1.1e25)&&(b < 10), b++; c*=1.23}
C eq:
while ((c<1.1e25)&&(b<10)) { b++; c*=1.23; }
All the shit (like variables) will be saved between calls if you'll use
/NOUNLOAD or setpluginunload alwaysoff.