|
|
This Parse_String(...) macro is new to me, so I played around with it, to see
what it could do. It's quite powerful, and opens up a lot of possibilities.
Btw, I like to take small chunks of code (like macros) out of include files and
put them directly into my scenes; this saves a *little* bit of parsing time--
and I can easily refer to them.
Some simple examples of the macro's use. (You can run all of these as a scene,
to see the results on-screen and in the messages pane):
//---------
#version 3.8; // or whatever
// the macro
#macro Parse_String(String)
#fopen FOut "parse_string.tmp" write // or "MY_FILE.inc" for example
#write(FOut,String)
#fclose FOut
#include "parse_string.tmp" // ditto
//------
// some initial values to work with
#declare S = seed(37);
#declare T = 6 + sqrt(4) + rand(S);
#declare MY_TEXT = concat("Hello"," ", "world!"," ",str(T,0,5)) // ANY kind of
// string
------
// a text object
text{
ttf "timrom.ttf" // or internal 1
Parse_String("MY_TEXT"),.2,0 // needs the double quotes here, because the
// macro's written file doesn't create those
translate <-4,0,15>
texture{pigment{rgb 1}finish {ambient 1 emission 0 diffuse 0}}
}
//--------
// Using the macro to CREATE a #declare statement. The macro (invisibly)
// inserts the statement #declare ZZ = 4; into the
// scene here-- not as a 'string', but as an actual command with a
// usable 'R-value'
#declare P = "#declare XX = 4;"
Parse_String(P) // using the macro
#declare TEST_1 = XX + 6; // The result is 10 as expected
// to test this final value
#debug concat("\n","TEST_1 = ",str(TEST_1,1,3),"\n")
//--------
// and similarly... writing TWO #declare statements on separate lines...
#declare P = concat("#declare XX = 4;","\n","#declare YY = 20;")
Parse_String(P)
#declare TEST_2 = XX + YY; // the result is 24 as expected
// to test this final value
#debug concat("\n","TEST_2 = ",str(TEST_2,1,5),"\n")
Post a reply to this message
|
|