POV-Ray : Newsgroups : povray.unofficial.patches : MegaPOV quirks and questions.. : Re: MegaPOV quirks and questions.. Server Time
2 Sep 2024 06:15:50 EDT (-0400)
  Re: MegaPOV quirks and questions..  
From: Chris Huff
Date: 25 Jul 2000 12:10:46
Message: <chrishuff-4FCD98.11111925072000@news.povray.org>
In article <397DA722.A87A6A01@peak.edu.ee>, Margus Ramst 
<mar### [at] peakeduee> wrote:

> #macro a(foo)
>    #if (foo)
>      #declare Switch=1;
>    #else
>      #declare Switch=0;
>    #end
> #end
> 
> #if(Switch)
>    #macro b()
>       // do one thing
>    #end
> #else
>    #macro b()
>       // do another thing
>    #end
> #end

In that case, you have to use that #if() statement after every time you 
call a(). Not very user-friendly...a better solution would be this:

// set a "default" macro
#declare Switch = 1;

#macro B1(foo)...#end
#macro B2(foo)...#end

#macro A(Foo)
    #if(Foo)
        #declare Switch = 1;
    #else
        #declare Switch = 2;
    #end
#end


// Code which would be calling B() if nested declarations were allowed.
#if(Switch == 1)
    B1(Foo)
#else
    B2(Foo)
#end

And of course, for more than two versions of the macro, you simply use a 
#switch() statement. You could even put this in yet another macro, to 
hide the fact that one of several macros is being picked, like this:
#macro B(Bar)
    #if(Switch == 1)
        B1()
    #else
        B2()
    #end
#end

Another possible workaround would be to put the macros in separate 
include files, and have a macro include different files depending on 
which one you want. You can't nest a #macro within a #macro, but maybe 
you can nest a #macro within an #include within a #macro...I haven't 
actually tried it, though, and it seems like a messy way to code.

-- 
Christopher James Huff - Personal e-mail: chr### [at] maccom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://homepage.mac.com/chrishuff/
TAG Web page: http://tag.povray.org/


Post a reply to this message

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