POV-Ray : Newsgroups : povray.newusers : Returning values from macros : Re: Returning values from macros Server Time: 8 Mar 2021 13:06:45 GMT
  Re: Returning values from macros  
From: JimT
Date: 3 Jun 2016 19:50:00
"Bald Eagle" <cre### [at] netscapenet> wrote:
> So, I just finished hunting down an old post by Jaap Frank about working around
> the official limitation on datan types in arrays.
>
> Just thought I'd repost the link as a reminder, since that was 13 years ago.  :)
>
>
http://news.povray.org/povray.text.tutorials/thread/%3C3f13449b$1@news.povray.org%3E/

I hesitate to try to add to what clipka says but...

If you #declare anything in a #macro, it is a global variable and will be known
outside the #macro and will assign a value to that variable name outside the
#macro, which is, of course usually a bad idea. Defining and assigning values to
local variables inside a #macro is what #local is for.

You can use #local to re-assign values to #macro arguments, even though they
must already have been defined outside the #macro before they are passed.

The following will reliably export information out of a #macro using arguments.
Of course, you don't need to define an object inside a #macro, though I have
here.

#version 3.7;
global_settings{assumed_gamma 1.0}
//
#include "colors.inc"
//
#macro in_and_out(num_in,num_out,vec_out,arr_out)
//
  #local num_out = num_in + 2;
  #local vec_out = <num_in+1,num_in+2,num_in+3>;
  #local icount  = 0;
  #while(icount < num_in)
    #local arr_out[icount] = icount+1;
    #local icount = icount + 1;
  #end
//
  sphere{<0,0,0> num_in pigment{Red}}
//
#end
//
#declare MMM_in  = 5;
#declare MMM_out = 0;
#declare MMM_vec = <0,0,0>;
#declare MMM_arr = array[MMM_in];
//
in_and_out(MMM_in,MMM_out,MMM_vec,MMM_arr)
//
sphere{MMM_vec, 1 pigment{Green}}
//
#warning concat("Last value of the array = ",str(MMM_arr[MMM_in-1],8,3))
//
light_source{ <100,100,-300>, 1}
//
camera{orthographic  location<0,0,-200> look_at <0,0,0> angle 15}


Post a reply to this message

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