POV-Ray : Newsgroups : povray.programming : Passing macros as macro arguments ? : Re: Passing macros as macro arguments ? Server Time
26 Apr 2024 06:52:18 EDT (-0400)
  Re: Passing macros as macro arguments ?  
From: Sktx
Date: 15 Jan 2010 03:30:00
Message: <web.4b5026b3c982c557b9d39f9d0@news.povray.org>
Christian Froeschlin <chr### [at] chrfrde> wrote:
> I was going to say it's not supported by the language, but you may
> in fact bend the rules a little if you write each macro body into
> a separate source file, so by passing the macro name you can then
> actually include code as required.
>
> I just made the following sample:
>
> --- BEGIN mymacro.inc ---------------
> // #macro mymacro(VALUE)
>
> // Map generic parameter names to functional names
> #local VALUE = P1;
>
> // Actual macro body
> #debug concat("MyMacro Invocation: ", str(VALUE,1,3), "\n")
> --- END mymacro.inc ---------------
>
>
> --- BEGIN user.pov ---------------
> // Sample for misusing include files to allow passing macros as
> // parameters to other macros.
>
> // Note that both include file macro bodies and local
> // macro wrappers need to follow a fixed naming convention
> // such as P1,P2,P3,... for the parameter names. Of course,
> // the number of parameters must be known in advance as it
> // forms the signature contract for the expected macro.
>
> // There may be restrictions regarding nesting and cycles.
>
> #macro MetaMacro(MACRO_NAME,VALUE)
>
>    #macro LOCAL_MACRO(P1)
>      #include concat(MACRO_NAME,".inc")
>    #end
>
>    LOCAL_MACRO(VALUE)
>
> #end
>
> // Invocation
>
> MetaMacro("mymacro",5)
> --- END user.pov ---------------

Seems very unpractical to me in the way I have to employ it, but still, good to
know that little trick ! Thanks for answering it.


Post a reply to this message

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