1831
HTML & templates / Re: Macros
« on: December 12, 2007, 06:55:48 PM »Quote
user created macros aka user created functions. The possibility to write a complex macro and place it in a user created function with custom parameters would be useful.
to call it {{call function | function-name | $A$ | $B$ |...}} A and B are the custom parameters.
to create {{function | function-name | $A$ | $B$ |...}}{{the macros to execute}} A and B define the parameters just like in javascript function (A,B,C){}...
eg {{call function | addition | 1 | 3 | 5}} 9 would be returned.
{{function | addition | $A$ | $B$ | $C$}}{{{{add | $A$ | $B$ | $C$}}}}
or you could even have the commands to execute as the last parameter, so the example above would be
{{function | addition | $A$ | $B$ | $C$ | {{add | $A$ | $B$ | $C$}}}}
Edit: Simple addition and subtraction, etc would be useful. Im working on something now that I must subtract one number from another so i know how many times to repeat itself.
Quote
{{ define | left{{#str|#len}} | {{cut | 0 | #len |#str }} }}
After a lot of reflection, I think of having found the solution:
To overload a macro or define a macro instead of the other one, we can use this macro
{{yourmacro|A|B|C|D|.....}} to use it
parameters A,B,C,D,.... are passed in this order $1,$2,$3,$4,..... to the overloaded macro
to define your macro you must use
{{define| yourmacro| {{one_macro|$1|$2|$3|$4}} }}
you can invert some parameters as ...
{{define| yourmacro| {{one_macro|$4|$2|$1|$3}} }}
...to accommodate the order of your parameters in agreement with the macro overloaded
by sample {{ define | left | {{cut|0|$1|$2}} }} usage {{left|($1)|$2}}
It will be possible to extend to more macros as
{{define| yourmacro | {{firstmacro|$3|$4}} {{secondmacro|$1|$2|$3}} {if|$4| then|else}} {{$5}} }}
but is is important that $5 must be passed as '$name' with the $ before name, otherwise the call of macro {{$name}} will not work, the risk is that you obtain {{name}} on the place.