![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
How hard would it be to implement this feature:
If an identifier appears in the script with a certain syntax, eg:
`identifier` or $identifier$ or #identifier# or whatever,
then that expression is substituted with the value of the identifier and
then parsing is continued exactly as if that value had been written
explicitly in that place.
For example (supposing that we use for example the $$ notation) this:
#declare MyIdentifier = "Another"
#declare $MyIdentifier$ = 5;
#declare Something$Another$ = <1,2,3>;
would be parsed exactly as if we had written:
#declare MyIdentifier = "Another"
#declare Another = 5;
#declare Something5 = <1,2,3>;
Why I propose this?
There is a discussion in povray.general (IIRC) about how to avoid unnecessary
parsing of include files that are #included more than once.
I thought that perhaps a macro could be done to automatize the ignoring
of repeated. This macro could be used like:
import("myinclude.inc")
which would #include "myinclude.inc" only if it wasn't included before.
It's not easy to implement this macro with the current povray script.
Perhaps simulating some dynamic array and searching that array could be
done, but that's hard to do and very slow when there are lots of includes.
Then I thought about the feature I propose here. The macro could be done
like:
#macro import(file)
#local ID = strreplace(file, ".", "_");
#ifndef(_INCLUDED_$ID_)
#declare _INCLUDED_$ID$_
#include file
#end
#end
(Note also the need for a 'strreplace' function or macro...)
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Dirty trick is to add filter before POV parser, but connected to it
(with access to parser's namespace).
With includes you have good idea. I tried this:
#declare Include="colors.inc"
#include Include
sphere {
<0, 0, 0>, 1
texture {
pigment {color Red}
finish {ambient 1}
}
}
and it works. Thus import macro can get string as its parameter.
Disnel
Warp wrote:
>
> How hard would it be to implement this feature:
>
> If an identifier appears in the script with a certain syntax, eg:
>
> `identifier` or $identifier$ or #identifier# or whatever,
>
> then that expression is substituted with the value of the identifier and
> then parsing is continued exactly as if that value had been written
> explicitly in that place.
> For example (supposing that we use for example the $$ notation) this:
>
> #declare MyIdentifier = "Another"
> #declare $MyIdentifier$ = 5;
> #declare Something$Another$ = <1,2,3>;
>
> would be parsed exactly as if we had written:
>
> #declare MyIdentifier = "Another"
> #declare Another = 5;
> #declare Something5 = <1,2,3>;
>
> Why I propose this?
> There is a discussion in povray.general (IIRC) about how to avoid unnecessary
> parsing of include files that are #included more than once.
> I thought that perhaps a macro could be done to automatize the ignoring
> of repeated. This macro could be used like:
>
> import("myinclude.inc")
>
> which would #include "myinclude.inc" only if it wasn't included before.
>
> It's not easy to implement this macro with the current povray script.
> Perhaps simulating some dynamic array and searching that array could be
> done, but that's hard to do and very slow when there are lots of includes.
> Then I thought about the feature I propose here. The macro could be done
> like:
>
> #macro import(file)
> #local ID = strreplace(file, ".", "_");
> #ifndef(_INCLUDED_$ID_)
> #declare _INCLUDED_$ID$_
> #include file
> #end
> #end
>
> (Note also the need for a 'strreplace' function or macro...)
>
> --
> main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
> ):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"Warp" <war### [at] tag povray org> wrote...
> I thought that perhaps a macro could be done to automatize the ignoring
> of repeated. This macro could be used like:
>
> import("myinclude.inc")
>
> which would #include "myinclude.inc" only if it wasn't included before.
>
> It's not easy to implement this macro with the current povray script.
It's not that hard. Here it is with comments. I don't think it would be
too slow, either. You've got to do the string comparisons somewhere, either
when you do token comparisons to find the identifier in the identifiers
table or when you search through the array like in this macro.
-Nathan
================
#macro Import(File)
// uncomment this to be case insensitive
//#local File=strupr(File)
// set up some variables
#ifndef(ImportFileList)
// we only keep track of a limited number of includes
#declare MaxImportFiles=50;
#declare ImportFileList=array[MaxImportFiles]
#declare NumImportsUsed=0;
#end
// look through the list to see if we've already
// included it
#local I=0;
#local Found=0;
#while(I<NumImportsUsed & Found=0)
#if(strcmp(ImportFileList[I],File)=0)
#local Found=1;
#else
#local I=I+1;
#end
#end
// if we didn't find it, let's include it
#if(Found=0)
// but first let's make a note that we are including
// it so we won't import it again
// if we've gone over the max, just don't bother
// (it will get re-included)
#if(NumImportsUsed<MaxImportFiles)
#declare ImportFileList[NumImportsUsed]=File
#declare NumImportsUsed=NumImportsUsed+1;
#end
// now do the include
#include File
#end
#end
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
There are only two problems here: It limits the amount of includes
and it reads through a long array each time (although I don't know how
povray handles identifiers, but I suppose it's faster than searching in
an array).
But you are right, it should work for most cases.
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |