POV-Ray : Newsgroups : povray.general : Is it possible to convert a text string to a Macro Identifier ??? : Re: Is it possible to convert a text string to a Macro Identifier ??? Server Time
1 Aug 2024 16:30:10 EDT (-0400)
  Re: Is it possible to convert a text string to a Macro Identifier ???  
From: Jim Charter
Date: 15 Aug 2005 11:05:29
Message: <4300af39$1@news.povray.org>
Mike E. wrote:
> I am trying to read a text file and call macros according to the names in
> the file WITHOUT using a look up table with #if #else or #switch etc.
> eg:
> 
> assume the text file is: "ROTATE_LEFT","ROTATE_RIGHT",..
> 
> #macro ROTATE_LEFT()
> blah blah
> #end
> 
> #macro ROTATE_RIGHT()
> blah blah
> #end
> 
> #read (MyFile,NAME)
> 
> NAME() // call the macro ROTATE_LEFT()
> 
> - I know this is illegal but this demonstrates what I would like to do, is
> there some way I can convert the text string directly to a macro
> identifier?
> 
> 
There is a macro, Parse_String(String) in the strings.inc file that can 
sometimes help to get the behavior you want.  I am not sure if it is 
relevant to your particular need here but in general it offers a way to 
have a string that you have composed dynamically somehow, appear to the 
parser just as if you had typed it in the source file.  My language here 
  may lack technical exactitude but for instance here is a snippet of 
code I am currently using:

#local I=0;#while(I<Grain)

         #local SplineDef =
	#concat ( "#declare Length_Spline_", str(I,0,0), " = " );				
         Parse_String(SplineDef) 

         spline { ....

#local I=I+1;#end


Post a reply to this message

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