POV-Ray : Newsgroups : povray.newusers : File handle and macros : Re: File handle and macros Server Time
1 May 2025 18:21:47 EDT (-0400)
  Re: File handle and macros  
From: kurtz le pirate
Date: 1 May 2025 04:44:55
Message: <68133487$1@news.povray.org>
On 30/04/2025 19:20, Bald Eagle wrote:
> kurtz le pirate <kur### [at] freefr> wrote:
> 
>> So we can't pass a file handle as a parameter ?
> 
> https://wiki.povray.org/content/Reference:File_I/O_Directives
> 
> 
> 
> You can use ifdef and defined, so I'm wondering if it's just a special kind of
> identifier that gets handled a little differently - just like things in the
> scene parser get handled differently by the function VM.
> 
> Try assigning another identifier the value of your file handle.
> 
> #declare Temp = FILE_HANDLE_IDENTIFIER;
> 
> try sending its value to the debug stream
> 
> basically try operating on it in any way that you can think of, and then maybe
> there's some sort of workaround that might be possible.
> 
> The other option is to use parse_string to use the literal name of the file
> handle as a string argument to your macro, and then parse it _inside_ your macro
> as an identifier.  Because the string and the identifier are two different
> things.


Thank you for your advice but in what I was hoping to do "parse_string" 
is not suitable.



An other test.
--------------------------------------------------------------------------
#macro fwrite (FileHandle, texte)
	#write (FileHandle, concat(texte,"\n") )
#end

#fopen FileHandle1 "test1.txt" write
#fopen FileHandle2 "test2.txt" write
#fopen FileHandle3 "test3.txt" write

fwrite (FileHandle1, "writing to test1")
fwrite (FileHandle2, "writing to test2")
fwrite (FileHandle3, "writing to test3")

#fclose FileHandle3
#fclose FileHandle2
#fclose FileHandle1
--------------------------------------------------------------------------

Give the same error : Parse Error: Expected 'macro parameter', file 
identifier found instead.



For #fopen, the doc say : "The file handle identifier created by #fopen 
is always global and remains in effect (and the file remains open) until 
the scene parsing is complete or until you #fclose the file."



Conclusion : The file handle is an IDENTIFIER, that we cannot store in 
variable.





Of course this code work :
--------------------------------------------------------------------------
#fopen FileHandle1 "test1.txt" write
#fopen FileHandle2 "test2.txt" write
#fopen FileHandle3 "test3.txt" write

#write (FileHandle1, "writing to test1\n")
#write (FileHandle2, "writing to test2\n")
#write (FileHandle3, "writing to test3\n")

#fclose FileHandle3
#fclose FileHandle2
#fclose FileHandle1
--------------------------------------------------------------------------

...but the advantages of having one and only one macro that writes to 
files are lost :(






-- 
kurtz le pirate
compagnie de la banquise


Post a reply to this message

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