POV-Ray : Newsgroups : povray.general : #ifdef using a string expression? : Re: #ifdef using a string expression? Server Time
9 May 2024 05:46:38 EDT (-0400)
  Re: #ifdef using a string expression?  
From: Bald Eagle
Date: 11 Apr 2023 13:30:00
Message: <web.6435984498df09c91f9dae3025979125@news.povray.org>
"Kenneth" <kdw### [at] gmailcom> wrote:
> I recently had a need for it:
>      #ifdef(AA & BB)
>
> Apparently, it doe not (yet) work with 'tuples' like the newer v3.8 #declare
> does, for example. Nor with boolean operators, so it seems.

> Any suggestions or comments? It seems to me that at least one of these schemes
> *should* work, unless I'm making a basic error or wrong assumption somewhere.


Depending on how many variables you need to test, you lump them all together
into an array and cycle through them, using the product of the result as a sort
of Boolean AND result.

Not sure I knew about "defined" - that's a handy keyword.

#declare AA = 1;
#declare BB = 3;

#declare Variables = array {AA, BB}


#macro And (_Array)
 #declare Elements = dimension_size (_Array, 1)-1;
 #declare AndResult = 1;
 #for (Index, 0, Elements)
  #declare AndResult = AndResult * defined (_Array[Index]);
 #end

 AndResult
#end


#if (And (Variables))
 #debug "All variables are defined. \n"
#end

#error "No objects in scene"d


Post a reply to this message

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