POV-Ray : Newsgroups : povray.general : Yet another SDL hack : Yet another SDL hack Server Time
2 Aug 2024 12:16:54 EDT (-0400)
  Yet another SDL hack  
From: Florian Brucker
Date: 18 Oct 2004 12:27:03
Message: <4173eed7$1@news.povray.org>
I thought I'd share this little piece of code:

--- %< snip %< ---
#include "strings.inc"

#macro IFDEF(Name)                                                   	
	#local Test = concat("defined(",Name,")?yes:no");
	(Parse_String(Test))
#end

#macro Set_Default_Value(_Name,_Value)
	#if (!IFDEF(_Name))		
		#declare _Set_Default_Value_Temporary = _Value;
		Parse_String(concat("#declare ",_Name," = _Set_Default_Value_Temporary;"))
		#undef _Set_Default_Value_Temporary
	#end
#end
--- %< snap %< ---

Using the second macro, you can set a default value for identifiers, 
even if they do not exist, i.e. it's an replacement for the following 
construct:

#ifndef (_Name) #declare _Name = _Value; #end

is the same as

Set_Default_Value("_Name",_Value);

(Please note the "" around the identifier's name!).

This does not really reduce the amount of typing or something like that, 
but I like it because it's more readable (IMHO) and it's only meant to 
be an illustration for similar, but more complicated macros.

BTW: The first macro can be used to check if an identifier whose name is 
the content of the given string is defined, e.g.

#if (IFDEF("my_first_identifier"))
	#debug "It does exist\n"
#end

Again, not really helpful for "standard" scenes, but very nice if you're 
doing lots of things with Parse_String (which is propably the most 
powerfull macro I've ever seen in SDL :)


HTH,
Florian
-- 
camera{look_at-y*10location<8,-3,-8>*10}#local a=0;#while(a<999)sphere{
#local _=.01*a-4.99;#local p=a*.01-5;#local c=.01*a-4.995;<sin(p*pi)*5p
*10pow(p,5)*.01>sin(c*c*c*.1)+1pigment{rgb 3}}#local a=a+1;#end
/******** http://www.torfbold.com ******** http://www.imp.org ********/


Post a reply to this message

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