POV-Ray : Newsgroups : povray.advanced-users : Macros in Macros? Server Time
25 Nov 2024 12:45:55 EST (-0500)
  Macros in Macros? (Message 1 to 8 of 8)  
From: Tim Nikias
Subject: Macros in Macros?
Date: 19 Oct 2002 10:09:24
Message: <3db16794@news.povray.org>
It obviously does work, but I've still got a question
regarding this:

I've fumbled around with my Particle-System. It formerly
was just a simple #include-file, and after setting all
parameters, you include it, and everything is
done.
Now, I've simply put a #macro-statement at the beginning
of the file, and an #end at the very end. Thus, by calling
PartixGen() its like including the file.

Now this:
I always thought that parameters and variables etc are
just temporarily stored while in the macro, and that
they are destroyed and the memory is set free after
the macro "destructs". Now I've got a macro-declaration
inside the include-file, which makes it possible to
visualize the emitter. But since the macro is inside an
already destruced macro, shouldn't it produce and error,
telling me the macro doesn't exist?
Is there something funky about macros and their declaration
in macros themselves? Just curious, it works like I want it
to, but its not what I actually expect.

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde


Post a reply to this message

From: Rune
Subject: Re: Macros in Macros?
Date: 19 Oct 2002 10:57:47
Message: <3db172eb$1@news.povray.org>
Tim Nikias wrote:
> Now this:
> I always thought that parameters and variables
> etc are just temporarily stored while in the
> macro, and that they are destroyed and the memory
> is set free after the macro "destructs".

While this is the case when you use #local, it is not the case when you
use #declare (except under special conditions). So it's not a general
rule. Since #macros neither use the #declare, nor the #local keyword
when they are defined, there's no reason to assume that they have the
same scope as either #declared variables or #local'ed variables. #macros
always have global scope, though I'm not sure if it's mentioned in the
documentation.

Rune
--
3D images and anims, include files, tutorials and more:
rune|vision:  http://runevision.com (updated Sep 8)
POV-Ray Ring: http://webring.povray.co.uk


Post a reply to this message

From: Mike Williams
Subject: Re: Macros in Macros?
Date: 19 Oct 2002 12:00:59
Message: <I63pDAArEYs9EwvB@econym.demon.co.uk>
Wasn't it Tim Nikias who wrote:
>It obviously does work, but I've still got a question
>regarding this:
>
>I've fumbled around with my Particle-System. It formerly
>was just a simple #include-file, and after setting all
>parameters, you include it, and everything is
>done.
>Now, I've simply put a #macro-statement at the beginning
>of the file, and an #end at the very end. Thus, by calling
>PartixGen() its like including the file.
>
>Now this:
>I always thought that parameters and variables etc are
>just temporarily stored while in the macro, and that
>they are destroyed and the memory is set free after
>the macro "destructs". Now I've got a macro-declaration
>inside the include-file, which makes it possible to
>visualize the emitter. But since the macro is inside an
>already destruced macro, shouldn't it produce and error,
>telling me the macro doesn't exist?
>Is there something funky about macros and their declaration
>in macros themselves? Just curious, it works like I want it
>to, but its not what I actually expect.

#local variables only exist within the macro that uses them, or, if
declared in an include file outside a macro, exist until the end of that
file.
#declare variables are global in scope and permanent in duration.
(see Doc: 6.2.2.2)

All macro names are global in scope and permanent in duration. 
(see Doc: 6.2.8.1: )

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Tim Nikias
Subject: Re: Macros in Macros?
Date: 20 Oct 2002 18:58:57
Message: <3db33531$1@news.povray.org>
Hm... Lets just describe this:
An include file contains a macro. Only an
object-declaration inside this macro is
declared, everything else is local...

So, when I call the macro, the declared
object is accessable. Now, inside the
macro, other files are included (which I did
a long time ago to keep different cores
of algorithms apart and easy accessable
for further development). Certain parts
now have to be declared, in order for
the macro to see the thereby generated
data... Right?

Hm. But all #local of the macro are visible
to the included files (checked that one), but
what if I change them inside the included
files? Using locals creates a new parameter
local to that file. Does #declare now use the
formerly local value to the macro, or does it
overwrite it?
And then, after I've used declare, are those
values visible when the macro has finished?
I'll fiddle with it, but I hope that someone might
have an answer (would be quite painful if this
doesn't work out...).

Regards,
Tim


--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde

>
> #local variables only exist within the macro that uses them, or, if
> declared in an include file outside a macro, exist until the end of that
> file.
> #declare variables are global in scope and permanent in duration.
> (see Doc: 6.2.2.2)
>
> All macro names are global in scope and permanent in duration.
> (see Doc: 6.2.8.1: )
>
> --
> Mike Williams
> Gentleman of Leisure


Post a reply to this message

From: Tim Nikias
Subject: Re: Macros in Macros?
Date: 20 Oct 2002 19:09:03
Message: <3db3378f@news.povray.org>
Okay, it works, almost like I expected it to...

When a #local (from inside an #included
file inside a macro) needs to be changed in
yet another included file (which is included inside
the macro which is included the original file),
using #local would create a #local to that
file. When using #declare, it accesses the #local
parameter of the original included file, but since
it is local inside the macro, it will be destroyed
when the macro is finished.

Quite difficult to think through, but works as
is expected. One has to think of the macro and
locals within as a capsule, which itself has again
local and global. Using declare of a local file
is so to speak global to the macro, but still
local to the original file which has included the
file in which the macro is set...

Phew. Quite difficult. Now that I'm working
in "layers", I hope I get everything done the correct
way... :-)

Regards,
Tim

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde


Post a reply to this message

From: hughes, b 
Subject: Re: Macros in Macros?
Date: 20 Oct 2002 22:20:05
Message: <3db36455$1@news.povray.org>
Sure wish I understood what you said, I could learn something about it
myself. That's a lot of forethought to go through.

:-)


Post a reply to this message

From: Shay
Subject: Re: Macros in Macros?
Date: 21 Oct 2002 18:02:35
Message: <3db4797b$1@news.povray.org>
Yes, I have written some includes like this. I have used this technique to
create a pseudo SDL with a scene file in order to make my macro calls
shorter. Something like this:

#macro Make_Tri (Tons of parameters)

#macro Start_Mesh (Tons of parameters)
  #macro Make_Triangle (Basic parameters)
    Make_Tri (Basic parameters + tons of parameters)
  #end  //  #macro Make_Triangle
#end  // #macro Start_Mesh

// *******
// **usage
// *******

Start_Mesh (Tons of parameters)
Make_Triangle (Basic parameters 1)
Make_Triangle (Basic parameters 2)
etc.
etc.

   -Shay

Tim Nikias <tim### [at] gmxde> wrote in message
news:3db16794@news.povray.org...


Post a reply to this message

From: Tim Nikias
Subject: Re: Macros in Macros?
Date: 21 Oct 2002 18:14:41
Message: <3db47c51$1@news.povray.org>
I should have come up with this way earlier. Would
have made my task much easier... Ah well, it just pays
to keep learning...

Regards,
Tim

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Email: Tim### [at] gmxde

> Yes, I have written some includes like this. I have used this technique to
> create a pseudo SDL with a scene file in order to make my macro calls
> shorter. Something like this:
>
> #macro Make_Tri (Tons of parameters)
>
> #macro Start_Mesh (Tons of parameters)
>   #macro Make_Triangle (Basic parameters)
>     Make_Tri (Basic parameters + tons of parameters)
>   #end  //  #macro Make_Triangle
> #end  // #macro Start_Mesh
>
> // *******
> // **usage
> // *******
>
> Start_Mesh (Tons of parameters)
> Make_Triangle (Basic parameters 1)
> Make_Triangle (Basic parameters 2)
> etc.
> etc.
>
>    -Shay
>


Post a reply to this message

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