POV-Ray : Newsgroups : povray.text.scene-files : foreach macro : Re: foreach macro Server Time
25 Apr 2024 19:33:24 EDT (-0400)
  Re: foreach macro  
From: jr
Date: 14 Apr 2021 16:50:00
Message: <web.6077545ad564bfd479819d986cde94f1@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > I re-wrote the first, buggy version ...
> this second version ...

and now a snapshot of #3.  some new features, improved documentation.  I will
have to put in some more work to provide a good set of tutorial examples, a new
demo scene, etc, but would meanwhile ask interested parties to give 'Foreach' a
try, see which bugs still lurk :-).

not documented because I've only done two tests so far is nesting of 'Foreach'
calls; I have managed to call the macro from a payload macro (with different
array + payload, of course).

an example of calling 'Foreach' with the new 'Indices' and 'Arg' features:

#version 3.8;

global_settings {assumed_gamma 1}

#include "foreach.inc"

#declare A = array [2][2][3] {
  {{1, 2, 3}, {4, 5, 6}},
  {{7, 8, 9}, {10, 11, 12}}
};

#macro m_walka(i_, j_, k_, elem_, arg_)
  #local n_ = elem_ * elem_;
  #debug concat("m_walka i = ",str(i_,0,0),", elem = ",str(elem_,0,0),
          "  arg = '",arg_.foo,"' and ",str(arg_.bar,0,0),".\n")
#end

#declare foober = dictionary {
  .foo: "this is nice.",
  .bar: 12345
};

#declare D = dictionary {
  .Macro:   "m_walka",
  .Arg:     "foober",
  .Walk:    1,
  .To:      3,
  .Extra:   on,
  .Indices: on,
  .Verbose: on
};

Foreach(A, D)


enjoy, jr.


Post a reply to this message


Attachments:
Download 'foreach3.zip' (8 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.