|
|
Am 04.04.2021 um 19:48 schrieb Bald Eagle:
> Instead of a boolean, return an integer flag to be further processed.
> (POV-Ray treats any non-zero value as "true")
> Then you can initially process the result as a boolean like you do, but then
> have a follow-up procedure that instantiates the sphere, maybe using #select.
>
> Or maybe you can just do that with the simple "boolean" as well...
Just skimming the thread, but from what I'm gathering, it seems that the
crux of the matter is that there's some construct where a macro would
essentially have to emit ("return") _two_ values separately: A status
result (boolean, apparently) that would have to be plonked into an
`#if(BOOLEAN)`, and an object that would have to be plonked elsewhere.
Fun fact: Unless my memory has been badly scrambled in the days of my
abscence, modern POV-Ray v3.8 can do such exciting stuff, using
tuple-style assignments, like so:
#declare (Foo,Bar) = (VALUE1,VALUE2);
This allows you to design a macro that is structured like so (and as a
matter of fact the syntax was introduced for exactly this very purpose):
#macro Frobnitz()
// Construct the stuff we want to emit ("return")
#local V1 = ...;
#local V2 = ...;
// Actually emit ("return") the stuff, tuple-style
(V1,V2)
#end
And then invoke it from some other code like so:
#declare (Foo,Bar) = Frobnitz();
// test for `Foo`
#if(Foo)
// emit `Bar` to actually plonk it into the scene
object { Bar }
#end
Hope this helps.
Oh, and in case you have a macro that may not have an object to emit as
the second value, try this (IIRC think it should work):
#macro Frobnitz()
#if(GOOD)
#local V2 = ...;
(true,V2)
#else
(false,)
#end
#end
And then invoke it from some other code like so:
#declare Bar = sphere { ... } // provide default for Bar
#declare (Foo, optional Bar) = Frobnitz();
// test for `Foo`
#if(Foo)
// emit `Bar` to actually plonk it into the scene
object { Bar }
#end
(I'm not 100% sure I recall the `optional` semantics properly; IIRC it
leaves the variable unchanged if no value is given, but it might also
set it to undefined instead. Also, I'm not 100% the comma in `(false,)`
is necessary or not. It's docomented... somewhere.)
Oh, and of course array- and vector-style assignments were also
introduced on that occasion, just for funsies:
#declare A = array[2] {VALUE1,VALUE2};
#declare [Foo,Bar] = A; //(*)
#declare V = <VALUE1,VALUE2>;
#declare <Foo,Bar> = V;
(*) I _think_ that was the syntax. Mighth have been curly braces instead
of square brackets though, i.e `#declare {Foo,Bar} = A;`. Again, it's
documented... somewhere.
Post a reply to this message
|
|
|
|
clipka <ano### [at] anonymousorg> wrote:
> ... and here I am, trying to CLEAN UP the parser code...
> *shrieks in horror*
"No one expects the Spanish Inquisition!"
Yeah - I'm not personally editing anything in that source code any time soon.
But I will do a few backflips on the SDL side to create some ugly hacks that
mimic the desired functionality. As much as it sucked to implement, it worked
quite nicely, and I added some other things to invoke identifiers by numeric
identifier (so I could easily loop through all the defined objects in the scene
file) or an alias.
Gave a nice nesting diagram in the #debug stream too, labeling the entry and
exit of each control structure with a user-defined label.
Post a reply to this message
|
|