|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hi !
I would like to make some functions. But I found POV-Ray's functions very
limited : it seems it is not possible to use directives inside.
So I decided to use macro instead, since I want to use them once at parse time
only.
From what I had understood, the #macro works pretty much as if it replaced the
call with the content of the macro.
However, I'm trying to make macro that return a float value, so I tried
something like :
#macro MyMacro(arg)
#if (arg > 1)
5
#else
10
#end
#end
But it doesn't work...
I saw some exemples like that :
#macro MyMacro(arg)
#if (arg > 1)
#declare X=5
#else
#declare X=10
#end
#end
But it doesn't seem right, I don't like toying with global var from inside
functions like this, I feel like I could overwrite some previous val...
Is there a clean way to do this kind of things ?
Thanks :)
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
On 29.06.10 20:31, Gyscos wrote:
> Is there a clean way to do this kind of things ?
> Thanks :)
You might want to try the documentation: "2.2.2.8.4 Returning a Value Like a
Function" <http://www.povray.org/documentation/view/3.6.1/243/>
Also, check the sample files and includes provided with POV-Ray, they
contain lots and lots of examples.
Thorsten
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Wow, I understand what didn't work...
Well, partly...
I used the macro in a declare :
#declare MyVar = MyMacro(MyStuff);
But POV-Ray parsed the macro and found some #if and #else BEFORE the expected
semi-colon...
:-/
So I have to put the semi-colon IN the macro, and not in the #declare line...
:(
I think I'll use extra arguments to return the value instead...
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Am 29.06.2010 21:37, schrieb Gyscos:
> Wow, I understand what didn't work...
> Well, partly...
>
> I used the macro in a declare :
>
> #declare MyVar = MyMacro(MyStuff);
>
> But POV-Ray parsed the macro and found some #if and #else BEFORE the expected
> semi-colon...
>
> :-/
>
> So I have to put the semi-colon IN the macro, and not in the #declare line...
> :(
>
> I think I'll use extra arguments to return the value instead...
This one will do:
#macro MyMacro(arg)
#if (arg > 1)
#local RetVal = 5;
#else
#local RetVal = 10;
#end
RetVal
#end
Note that the value to be returned is stored in a local variable first,
which is then "returned" at the very end of the macro.
Extra arguments as return values are pretty cumbersome, as you'll always
have to make sure that the respective variable is defined properly
before being passed to (and back from) the macro.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Wow, cool :)
Post a reply to this message
|
|
| |
| |
|
|
From: kurtz le pirate
Subject: Re: How to use #Macro like a function ?
Date: 2 Jul 2010 08:35:32
Message: <4c2ddd14@news.povray.org>
|
|
|
| |
| |
|
|
news:4c2a530d$1@news.povray.org...
> Am 29.06.2010 21:37, schrieb Gyscos:
> ... #macro MyMacro(arg)
> #if (arg > 1)
> #local RetVal = 5;
> #else
> #local RetVal = 10;
> #end
> RetVal
> #end
> ...
#macro MyMacro(arg)
(arg>1)?5:10
#end
--
klp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
In article <4c2ddd14@news.povray.org>,
"kurtz_le_pirate" <kur### [at] yahoofr> wrote:
> #macro MyMacro(arg)
> (arg>1)?5:10
> #end
ooops...
#macro MyMacro(arg)
((arg>1)?5:10)
#end
--
klp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |