rejetto forum

Macros

Mars · 231 · 128033

0 Members and 1 Guest are viewing this topic.

Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
une autre idée me trotte dans la tête

can you update function inc() as this:

Quote
  procedure inc(v:integer=+1);
  begin
  if not satisfied(md.cd) then exit;
  try
  if not(md.cd.params.indexOf(p) >= 0) then md.cd.vars.values[p]:='0';
      result:='';
    with md.cd.vars do values[p]:=intToStr(strToInt(values[p])+v*parI(1,1))
  except end;
  end; // inc

Ainsi on pourra définir une variable à 0 par défaut (sans connaitre son nom à l'avance) simplement par un appel à INC ou DEC comme par exemple  {{inc|file.%item-ext%}}, car je ne peux prédire à l'avance quelles EXT seront utilisées dans %files%
et éviter d'utiliser   la combinaison {{set|count|{{count|file.%item-ext%}} /set}}  {{^count}}

mais plutôt  {{inc|file.%item-ext%}} et {{^file.%item-ext%}}

tout comme avec %sequential% il n'y a pas %number-sequential%
ainsi avec {{count|....}} il manque l'équivalent de {{special end|{{^count|....}}}}

donc au lieu d'avoir

{{set |myvar|0}}    .....   {{inc/dec|myvar|n}} ...  {{^myvar}} = n

alors
 {{inc|myvar|n}} ...  {{^myvar}} = n

serait équivalent et suffisant.



« Last Edit: January 03, 2008, 10:03:47 PM by mars »


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
DIV only works when dividing a number that has 9 or less digit's.

eg
{{div|999999999|1024}} returns 976562

but

{{div|9999999999|1024}} returns 0


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
limit is {{div|2147483647|1024}}

 
Quote
Min longint value = -2147483648
 Max longint value = 2147483647

rejetto must change storage to

Quote
Min int64 value = -9223372036854775808
 Max int64 value = 9223372036854775807

Quote
function parI(idx:int64; def:int64=0):int64;
  begin result:=strToIntDef(par(idx), def) end;

and more if necessary 






Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
64bit integers supported

inc now works with non-numeric vars. they will be considered zero.


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
Quote from: Wiki
All macros, except quoted ones, are expanded. Even if you use the macro if|A|B|C, independently by the value of A, both B and C are expanded. If A is true, C is discarded, and vice versa. This is an important point, because if you was using append inside C, the file will be written anyway.

After reading this I thought, why not have the if macro automatically apply quotes and then unquote the correct parameter.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
Because execution of macros is done when the parser already finished its work.
The parser have no knowledge of the macros, just handles parenthesis.

Another point is: you do {{append|file|{{another macro}} }}
How can HFS know that you want to execute another macro now or later ?
Think it works with url parameters. You may want to work with current parameters, or the parameters of the time you will load the file. Only you know.
And you will choose between behaviour 1 or 2 by quoting or not.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
It is the same difference when you define

{{set|myvar|{{cut|1|8|It is the same difference}} /set}}

and

{{set|mymacro| {{\ {{cut|1|$1|$2}}  /}} /set}}

if you use

{{append|file|{{another macro}} }}

{{another macro}} is immediatly evaluated and result is stored in file

but with

{{append|file| {{\ {{another macro}} /}} }}

it is  {{another macro}} who is stored in file

and when you include this file in your template {{load|file}}, it is here that the macro {{another macro}} is evaluated.


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
{{append|file| {{\ {{another macro}} /}} }}

it is  {{another macro}} who is stored in file

and when you include this file in your template {{load|file}}, it is here that the macro {{another macro}} is evaluated.


When I tested this the quotes were added to the file as well, so in this case it would be {{\{{another macro}}/}}.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
foggy i make test with


{{set|myvar|{{\{{\{{another macro}}/}}/}}}}
{{append| c:\file.txt|{{^myvar}}}}


see result on your template ;D ;D ;D
« Last Edit: January 04, 2008, 02:44:46 PM by mars »


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
Im about to goto bed so I'll test in the morning, but that looks like it will work :P

I'll use that in the mean time but I think It would be more simpler in the long run to just use dequote as rejetto suggested.


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
It works, but the problem is I'm trying to include a urlvar in the macro that is being written to file, so to create some dynamic content.

This is what I get in the file
{{set|Title|{{?title}}}}

I need to be able to evaluate the urlvar before it is written to file.


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
missing more code to evaluate where is your pb

by sample
{{set|myvar|{{\{{\{{another macro}}/}}/}}}}
{{append| c:\file.txt|{{^myvar}}}}

is full to work


Offline Foggy

  • Tireless poster
  • ****
    • Posts: 806
    • View Profile
where is your pb

pb ???

this is the code I tried, it works but the urlvar isn't evaluated before being written to file but I don't think there is a way around that.

{{set|data|{{\{{\{{set|Title|{{?title}}}}/}}/}}}}
{{append|{{?name}}.txt|{{^data}}}}

I think I'll have to go back to my first idea of creating a strings table and loading that instead.


Offline rejetto

  • Administrator
  • Tireless poster
  • *****
    • Posts: 13510
    • View Profile
does this work?

{{set|data|{{replace|$1|{{?title}}|{{\{{\{{set|Title|$1}}/}}/}}/replace}}}}
{{append|{{?name}}.txt|{{^data}}}}


Offline Mars

  • Operator
  • Tireless poster
  • *****
    • Posts: 2059
    • View Profile
note pour rejetto

{{\ ..... /}}  ok

{{\{{\ ..... /}}/}}  can be replaced by an alias as  {{\\..... //}}
{{\{{\{{\ ..... /}}/}}/}}  can be replaced by an alias as  {{\\\..... ///}}

update to do this
Quote
function dequote(s:string):string;
  begin
  if ansiStartsStr(MARKER_QUOTE+'\', s) and ansiEndsStr('/'+MARKER_UNQUOTE, s) then
     begin
        delete(s,length(s)-length(MARKER_UNQUOTE),1);
        delete(s,length(MARKER_QUOTE)+1,1);
        result:=s;
     end
  else
if ansiStartsStr(MARKER_QUOTE, s) and ansiEndsStr(MARKER_UNQUOTE, s) then
    result:=copy(s, length(MARKER_QUOTE)+1, length(s)-length(MARKER_QUOTE)-length(MARKER_UNQUOTE) )
  else
    result:=s
  end; // dequote

 chaque  {{\\\ ..... ///}} est remplacé par {{\\..... //}} qui est de nouveau remplacé par {{\ ..... /}} à chaque appel de dequote()
« Last Edit: January 05, 2008, 06:11:26 PM by mars »