POV-Ray : Newsgroups : povray.general : how to call multiple instances of a macro? : Re: how to call multiple instances of a macro? Server Time
30 Jul 2024 12:31:06 EDT (-0400)
  Re: how to call multiple instances of a macro?  
From: CShake
Date: 12 Mar 2009 02:15:38
Message: <49b8a88a$1@news.povray.org>
clipka wrote:
> #macro ParseLiteral(s)
>   #local FileName = "ParseLiteral_$$$.inc";
>   #fopen ParseLiteral_FD FileName write
>   #write (ParseLiteral_FD, s)
>   #fclose ParseLiteral_FD
>   #include FileName
> #end
> 
> #macro stringOfLights(Lamp,Center,Brightness)
>   #local i=1;
>   #while(i<10)
>     ParseLiteral(Lamp) (Center+i*x,Center+i*x+<point_vector>,Brightness)
>     #local i=i+1;
>   #end
> #end
> 
> stringOfLights("lamp1",<1,2,3>,10)
> 
> #local i=rand(R)*10;
> stringOfLights(concat("lamp", str(i,0,0)),<4,5,6>,10)
> 
> -------------
> 
> POV SDL may be cumbersome at times, but let nobody say it wasn't flexible...
> 
> 

Most helpful. Very much looks like a hack that wasn't exactly intended, 
but works perfectly.

I decided to use a slightly more segmented version to reduce a little 
bit of disk writing during parse:

#macro ParseLiteral(s)
   #declare ParsedLiteralFile = "ParseLiteral_$$$.inc";
   #fopen ParseLiteral_FD ParsedLiteralFile write
   #write (ParseLiteral_FD,s)
   #fclose ParseLiteral_FD
#end

#macro ParsedLiteral()
   #include ParsedLiteralFile
#end

......

ParseLiteral(macroName)
#local i=1;
#while(i<20)
   ParsedLiteral()(macro parameters)
   #local i=i+1;
#end

-------------

I wonder how much overhead this really causes, I figure that Christian 
Froeschlin's method of just using a selection macro and assigning 
numerical values to each macro name would be slightly more efficient 
when parsing, but involves more work for the user and is not very flexible.


Post a reply to this message

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