POV-Ray : Newsgroups : povray.general : Is there a more dynamic way of doing this... Server Time
1 Nov 2024 03:17:20 EDT (-0400)
  Is there a more dynamic way of doing this... (Message 1 to 3 of 3)  
From: FNH
Subject: Is there a more dynamic way of doing this...
Date: 26 Apr 2014 09:35:01
Message: <web.535bb4f96e27458fe247cf090@news.povray.org>
I have macro that calls other macros...

#macro generateTail()
        #declare tailType = int(rand(rnd)*3)+1;
        #switch(tailType)
                #case(1)
                        generateTail1()
                        #break
                #case(2)
                        generateTail2()
                        #break
                #case(3)
                        generateTail3()
                        #break
        #end
#end

If I want to add in a fourth generateTail macro, I have to update the random
statement, then add a new "case" statement into the "switch". Can I call a macro
dynamically, by perhaps adding the random number to "generateTail" and calling
the result?


Post a reply to this message

From: Christian Froeschlin
Subject: Re: Is there a more dynamic way of doing this...
Date: 1 May 2014 19:18:25
Message: <5362d641$1@news.povray.org>
On 26.04.2014 15:31, FNH wrote:

> If I want to add in a fourth generateTail macro, I have to update the random
> statement, then add a new "case" statement into the "switch". Can I call a macro
> dynamically, by perhaps adding the random number to "generateTail" and calling
> the result?

I've never tried this myself but I think it is possible to
generate code in the program (as text), write it to a file, and
then #include the generated file. So you could have a macro that
generates the switch statement for N macros.


Post a reply to this message

From: clipka
Subject: Re: Is there a more dynamic way of doing this...
Date: 26 May 2014 13:17:12
Message: <53837718$1@news.povray.org>
Am 02.05.2014 01:18, schrieb Christian Froeschlin:
> On 26.04.2014 15:31, FNH wrote:
>
>> If I want to add in a fourth generateTail macro, I have to update the
>> random
>> statement, then add a new "case" statement into the "switch". Can I
>> call a macro
>> dynamically, by perhaps adding the random number to "generateTail" and
>> calling
>> the result?
>
> I've never tried this myself but I think it is possible to
> generate code in the program (as text), write it to a file, and
> then #include the generated file. So you could have a macro that
> generates the switch statement for N macros.

It's perfectly possible indeed, and even exploited by a macro in 
strings.inc that executes a given string as POV-Ray SDL code.


Post a reply to this message

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