A directive is a statement that begins with # and a directive word. Directives are not a separate text pass. The parser runs them while it reads the scene: it evaluates their arguments, changes its tables of identifiers, opens files, and chooses which of the following tokens it reads and which it skips. A directive takes values from expressions (see Expressions, vectors and identifiers), so #if (A > 2 & B = 3) and #declare X = sin(Y) * 2; may use anything the language can compute at that point. How the # is read, and what happens to a # that is not followed by a directive word, is on Lexical structure.
The directive code is Parse_Directive in parser_tokenizer.cpp; the declaration code is Parse_Declare in parser.cpp. The program in 3.8 has 28 directive words (a 29th, #breakpoint, exists only in debug builds).
All directives
| Directive | Syntax | What it does |
|---|---|---|
#declare | #declare Name = value; | defines an identifier with global scope |
#local | #local Name = value; | defines an identifier that ends with the current file, include file or macro run |
#default | #default { items } | changes the default texture, pigment, normal, finish, radiosity importance or camera |
#undef | #undef Name | removes an identifier |
#macro | #macro Name(params) ... #end | defines a macro |
#include | #include "file" | reads another file here |
#version | #version number; | sets the language version |
#if | #if (cond) ... [#elseif (cond) ...] [#else ...] #end | conditional |
#ifdef | #ifdef (Name) ... [#else ...] #end | conditional on a name being declared |
#ifndef | #ifndef (Name) ... [#else ...] #end | conditional on a name not being declared |
#elseif | #elseif (cond) | another condition of an #if |
#else | #else | the alternative branch; also the default branch of a #switch |
#end | #end | closes the innermost open construct |
#while | #while (cond) ... #end | loop while a condition holds |
#for | #for (Var, start, end [, step]) ... #end | counting loop |
#switch | #switch (expr) #case (v) ... #break ... #end | multi-way conditional |
#case | #case (value) | a branch of a #switch |
#range | #range (low, high) | a branch for a range of values |
#break | #break | leaves the innermost loop, #case or macro |
#fopen | #fopen Id "file" read | write | append | opens a data file |
#fclose | #fclose Id | closes it |
#read | #read (Id, Name, ...) | reads values from a file |
#write | #write (Id, item, ...) | writes values to a file |
#debug | #debug string | writes a message to the debug stream |
#warning | #warning string | writes a warning; the parse goes on |
#error | #error string | stops the parse with a message |
#render | #render string | as #debug, with a warning |
#statistics | #statistics string | as #debug, with a warning |
The condition in parentheses is a full expression: comparisons, &, |, ! and ? : are allowed (a plain expression outside parentheses does not allow them; see the expressions page). The value is true when its absolute value is greater than 1e-10, so a float that is 0 or very close to 0 is false.
#declare and #local
Both directives define an identifier and give it a value. They differ in scope only. The value can be a float, a vector, a colour, a string, an array, a dictionary, a function, a spline, a transform, or a texture, pigment, normal, finish, interior, media, camera, object and so on (the full list is on the expressions page). The type of the identifier is the type of the value, and an identifier can be given a new value of another type later.
| Form | Meaning |
|---|---|
#declare Name = value; | declares one identifier. The semicolon is required after a float, vector or colour from language version 3.5 on (a missing one is an error), and accepted after any value |
#declare Name = value for an object, texture, camera and other blocks | the value is a block such as sphere { ... } or texture { ... }; a semicolon after it is accepted and not needed |
#declare (A, B, C) = (1, 2, 3) | declares several identifiers at once. An identifier or a value may be left out ((A, , C) = (1, 2, 3)); the value of a left-out identifier is thrown away |
#declare (D, optional E) = (4, ) | an optional identifier may have no value; it is then left undeclared |
#declare <X, Y, Z> = <1, 2, 3> | declares up to five floats from one vector expression; a single float is spread over all of them (<Left, Right> = 2 gives both the value 2) |
#declare { X, Y, Z } = Array | declares identifiers from the elements of a one-dimensional array, which must be at least as long as the list |
#declare deprecated [once] "message" Name = value; | marks the identifier as deprecated. Every use gives a warning with the message (once: only the first use). Without a message the warning says that the identifier was declared deprecated |
#declare Name[i] = value;, #declare Dict.name = value; | assigns an array element or a dictionary entry |
Scope
The parser keeps a stack of symbol tables. There is one global table at the bottom. A new table is put on top when a file is included and when a macro runs, and it is taken off again when the include or the macro ends. Braces { }, #if blocks and loops do not make a table.
| Directive | Where the identifier is stored | Visible until |
|---|---|---|
#declare | the global table | the end of the scene, or an #undef |
#local | the table on top of the stack | the end of the include file or the macro run that holds it; in the main file it behaves like #declare |
When #local names an identifier that exists in a lower table, it creates a new identifier in the top table and hides the older one until the top table goes away. When #declare names an identifier that is visible, it assigns to that identifier, wherever it is: after #local T = 1; #declare T = 2; in a macro, the local T is 2 and no global T exists (checked with the program). Declaring a function that already exists is an error (Redeclaring functions is not allowed - #undef the function first!). A macro or a file identifier cannot be the target of #declare or #local.
Macros do not capture the identifiers around their definition. The text of a macro is read again each time it runs, and a name in it is looked up in the tables of that moment. A macro defined in an include file that uses a #local of that file therefore fails when called from the main file (Expected 'numeric expression', undeclared identifier 'LocalInInc' found instead), because the local is gone by then.
#declare G = 1;
#local L = 2;
#macro Scope()
#local InMacro = 10;
#declare FromMacro = 20;
#declare G = G + 100;
#end
Scope()
#debug concat("G=", str(G, 0, 0), " L=", str(L, 0, 0), " FromMacro=", str(FromMacro, 0, 0), "\n")
#ifdef (InMacro)
#debug "InMacro visible\n"
#else
#debug "InMacro not visible\n"
#end
#undef G
#ifdef (G)
#debug "G still defined\n"
#else
#debug "G undefined\n"
#end
G=101 L=2 FromMacro=20, InMacro not visible and G undefined. The #local inside the macro is gone when the macro ends, the #declare inside it is global.#declare Arr = array[3] { 10, 20, 30 };
#declare { X, Y, Z } = Arr;
#declare (A, , C) = (1, 2, 3);
#declare (D, optional E) = (4, );
#declare <R, G2, B> = <0.1, 0.2, 0.3>;
#debug concat(str(X + Y + Z, 0, 0), " ", str(A + C, 0, 0), " ", str(D, 0, 0), " ", str(defined(E), 0, 0), " ", str(G2, 0, 1), "\n")
#declare deprecated once "use New instead" Old = 3;
#debug concat(str(Old, 0, 0), " ", str(Old, 0, 0), "\n")
#debug prints 60 4 4 0 0.2, and the program warns use New instead once, at the first use of Old.#undef
#undef Name removes an identifier from the table that holds it, so that #ifdef no longer finds it and the name can be declared again with another type. An array element can be removed as well. Undefining a name that is not declared only gives the warning Attempt to undef unknown identifier. A file identifier that is still open gives a warning that #fclose should be used instead.
#default
#default { item ... } changes what the parser uses when an object has no texture of its own, or when a texture has no pigment, normal or finish. The items are tried in a loop, so several can be given in one block.
| Item | Effect |
|---|---|
texture { ... } | replaces the default texture; it may not be a material map, tiles, or layered |
pigment { ... } | changes the pigment of the default texture |
normal { ... } | changes the normal of the default texture |
finish { ... } | changes the finish of the default texture |
radiosity { importance f } | the default radiosity importance, above 0 and at most 1 |
camera { ... } | sets the values of the default camera (Default_Camera in the parser) |
A default applies to objects that are read after it. See the example at the end of #version.
#macro
A macro is a named piece of scene text with parameters. It needs language version 3.1 or later. The definition is #macro Name(P1, P2, ...) ... #end; a macro without parameters has empty parentheses. A call is the name followed by a list of arguments in parentheses, Name(a, b), written wherever a statement or an object item may stand. A call may also be written with a hash, #Name(a, b) (the hash is dropped, see Lexical structure; checked with the program).
Parameters
| Item | Meaning |
|---|---|
| a plain name | a parameter that must be given in the call. Omitting it is the error Cannot omit non-optional macro parameter 2., and giving fewer arguments than parameters is Expected 2 parameters but only 1 found. |
optional Name | a parameter that may be left out. To leave it out the argument list still needs the comma that would come before it, with nothing after it: Greet("world",). Inside the macro, #ifdef (Name) tells whether it was given |
An argument can be any value that #declare accepts: an expression, a string, an object block, a texture and so on. Arguments are read when the call starts, before anything of the macro runs. If an argument is simply the name of an identifier that exists, the parameter is an alias for it: assigning to the parameter with #declare or #local inside the macro changes the caller's identifier. If the argument is any other expression, the parameter is a new identifier that holds the value and goes away with the call. An undeclared name as an argument is an error unless the parameter is optional (Cannot pass uninitialized identifier as non-optional macro parameter.).
How a macro is stored and run
The parser does not keep a parsed form of the body. When it reads #macro it records the name and the parameter names, notes where in the file the body starts (just after the closing parenthesis), and then skips tokens to the matching #end, counting any #if, #while, #for, #switch and #macro it passes, and notes where that #end is. A body of at most 65536 bytes is also copied into memory as raw text. The body must end in the file where it started. Macro names live in the global table whatever the scope of the place where they are defined, and defining a name again replaces the macro.
A call does this: it reads the arguments, remembers the place to return to, puts a new symbol table on the stack (it holds the parameters and the #local identifiers of this run), and then goes back to the body text and reads it again, token by token, as if it stood at the place of the call. When the reader arrives at the recorded #end, or at a #break that has no enclosing loop or #case in the macro, it returns to the call and drops the table. Because the body is read as source text in the context of the call, a macro can contain object statements (it is how Ball below adds a sphere), partial blocks, and further directives, and it can call itself. The code sets no limit on the depth of recursion or of nested calls.
Return values
A macro has no return statement. It passes values back in three ways: by #declare (global), by changing an identifier that the caller passed by name, or by the text that its body produces. The third way makes a macro usable inside an expression: the body is read at the place of the call, so a macro whose body is an expression (possibly after directives) gives that value. #macro Twice(X) (X * 2) #end then allows #declare R = Twice(4) + 1;, which gives 9 (checked with the program), and a macro body <A, B, 0> or a string works the same way. The standard files math.inc and transforms.inc use this form (VDist(P1, P2), vtransform(V, T)).
#macro Square(N)
#declare Result = N * N;
#end
Square(7)
#debug concat("Square(7) = ", str(Result, 0, 0), "\n")
#macro Greet(Name, optional Greeting)
#ifdef (Greeting)
#debug concat(Greeting, ", ", Name, "\n")
#else
#debug concat("Hello, ", Name, "\n")
#end
#end
Greet("world", "Good day")
Greet("world",)
Square(7) = 49, Good day, world and Hello, world.#macro Fact(N)
#if (N <= 1)
#declare FactResult = 1;
#else
Fact(N - 1)
#declare FactResult = FactResult * N;
#end
#end
Fact(5)
#debug concat("5! = ", str(FactResult, 0, 0), "\n")
#macro Ball(P, R)
sphere { P, R pigment { rgb <1, 0, 0> } }
#end
Ball(<0, 0, 0>, 1)
Ball(<2, 0, 0>, 0.5)
5! = 120 and adds two spheres to the scene. The recursion calls Fact again before the #declare that follows the call.#macro ChangeLocal(V)
#local V = 77;
#end
#macro Plain(V)
#debug concat("plain: ", str(V, 0, 0), "\n")
#end
#declare Mine = 1;
ChangeLocal(Mine)
#debug concat("Mine = ", str(Mine, 0, 0), "\n")
Plain(Mine + 1)
#macro Early(X)
#if (X > 0)
#debug "positive\n"
#break
#end
#debug "not positive\n"
#end
Early(1)
Early(-1)
Mine = 77 (the parameter is an alias for Mine), plain: 78 (an expression is a value), then positive and not positive. #break inside #if in a macro leaves the macro.#include
#include "file" reads another file at this place and then goes on after the directive. The argument is a string expression, so #include concat("scene", str(N, 0, 0), ".inc") works. The file is read as if its text stood where the directive is, with these differences: a new symbol table is put on the stack for the file (so #local in the include ends with the include), and the file must keep its #end directives balanced. An include file may include other files; the code has no limit on the depth.
The parser asks the front end to find the file. It tries the name with the extensions of the include file type (.inc and .INC) added, and the name exactly as given; if the name already ends in one of those extensions the exact name is tried first. Each name is looked for in the current directory (or, for a name with a drive or full path, only there), and then in the library paths (the +L option and the Library_Path INI option). Writing #include "colors" finds colors.inc. A file that cannot be found stops the parse: Cannot open include file name., after the message Cannot find file 'name', even after trying to append file type extension.
A file can start with a UTF-8 byte order mark; each included file is checked for it. How backslashes in the name are read depends on the language version, see Strings. The standard include files are on Include files.
// first.inc
#declare Shared = 1;
#local Private = 2;
#macro Report(X)
#debug concat("Report(", str(X, 0, 0), ") sees Shared=", str(Shared, 0, 0), "\n")
#end
#include "second.inc"
#debug "back in first.inc\n"
first.inc of the example. It includes a second file.// second.inc
#debug "in second.inc\n"
#declare FromSecond = 3;
second.inc.#include "first.inc"
#debug concat("Shared=", str(Shared, 0, 0), " FromSecond=", str(FromSecond, 0, 0), "\n")
#ifdef (Private)
#debug "Private is visible\n"
#else
#debug "Private is not visible\n"
#end
Report(5)
#include "second"
#include "colors.inc"
#debug concat("White = ", vstr(3, White, ",", 0, 1), "\n")
in second.inc, back in first.inc, Shared=1 FromSecond=3, Private is not visible, Report(5) sees Shared=1, in second.inc again (the name without extension finds second.inc) and White = 1.0,1.0,1.0 from the standard colors.inc, found through the library path.#version
#version number; sets the language version, the number of the POV-Ray release that the scene was written for. The parser stores it as the integer round(number * 100), so 3.8 is 380. The word version in an expression gives the current value. Many parts of the language change with the version, and each is listed on Versions.
| Form | Meaning |
|---|---|
#version 3.8; | the scene needs language 3.8; a version above that of the program is the error Your scene file requires POV-Ray version 9.9 or later! |
#version version; | sets the language version to the current value of version. This is the idiom for a scene (or include file) that adapts to the program |
#version unofficial 3.8; | says that the scene is for an unofficial build; an official build refuses it |
The directive may be used again later in the file, for instance to switch an include file to the old rules and back. The scene file should start with it: if the first #version comes after other statements and asks for 3.8 or later, the parser stops (As of POV-Ray v3.7, the '#version' directive must be the first non-comment statement in the scene file.). The semicolon is reported as missing (Possible Parse Error) when absent.
#debug concat("version = ", str(version, 0, 2), "\n")
#version 3.7;
#debug concat("version = ", str(version, 0, 2), "\n")
#default { pigment { rgb <1, 0, 0> } finish { diffuse 0.6 } }
sphere { 0, 1 }
#version 3.8;: it prints version = 3.80 and then version = 3.70. The sphere gets the default pigment and finish.#if, #ifdef, #ifndef, #elseif, #else
A condition opens a block that is closed by #end. At most one branch is read; the others are skipped without being run.
| Directive | Argument | The branch is read when |
|---|---|---|
#if (cond) | a float expression in parentheses | the value is true (absolute value above 1e-10) |
#ifdef (Name) | one name in parentheses | the name is declared. An array element is tested by whether it has a value. A reserved word gives the warning Trying to test whether a reserved keyword is defined. Test result may not be what you expect. |
#ifndef (Name) | the same | the name is not declared |
#elseif (cond) | as #if | no earlier branch was read and the condition is true. The condition is not evaluated when an earlier branch was read |
#else | none | no earlier branch was read |
A #else or #elseif without an open condition is an error (Mis-matched '#else'., Mis-matched '#elseif'.). The defined test defined(Name) can be used inside any expression, and an #ifdef on a file identifier is true until the file is closed.
What is read inside a skipped branch
A skipped branch is not tokenized. The scanner looks only for strings, comments and #, so any other text, even if it is not valid, is passed over without a message. A string is read whole, so a #end inside a string or comment does not end the branch, and an unmatched " is an error. A # in the branch is followed by its directive word: #if, #ifdef, #ifndef, #while, #for, #switch and #macro open a nested block that is skipped as a whole up to its own #end, and the directives #else, #elseif, #case, #range and #end of the open construct are acted on. Other directives in a skipped branch are ignored. An example of the checked skipping is on Lexical structure.
#declare V = 5;
#if (V < 3)
#debug "small\n"
#elseif (V < 10)
#debug "medium\n"
#else
#debug "large\n"
#end
#ifndef (Nothing)
#debug "Nothing is not defined\n"
#end
medium and Nothing is not defined.#while and #for
| Directive | Meaning |
|---|---|
#while (cond) ... #end | the condition is evaluated before the first pass and again at each #end. The body runs while it is true. The parser goes back to the #while by seeking to its position in the file, so the loop must end in the file where it began (#while loop did not end in file where it started.) |
#for (Var, start, end [, step]) ... #end | Var is a name that becomes a float in the current local table (an identifier of that name in a lower table is hidden, one in the same table is overwritten). start, end and step are float expressions, evaluated once. step is 1 when left out; a step of 0 is the error #for loop increment must be non-zero. |
The exact rule of #for: the body runs while Var has not passed end in the direction of the step. With a positive step the condition is Var <= end + 1e-10, with a negative step it is Var >= end - 1e-10. The condition is tested before the first pass, so a loop whose start is already beyond the end runs zero times. At each #end the step is added and the condition tested again. The end value is therefore included, and the tolerance keeps rounding errors of a fractional step from dropping it. After the loop Var still exists and holds the first value that failed the test. The loop variable must stay a float inside the loop; otherwise the parser reports #for loop variable must remain defined and numerical during loop. It cannot be an array or dictionary element.
#break in a loop leaves the innermost loop at once; it may be inside an #if in the loop.
#for (I, 1, 4)
#debug concat(str(I, 0, 0), " ")
#end
#debug "\n"
#for (I, 10, 4, -3)
#debug concat(str(I, 0, 0), " ")
#end
#debug "\n"
#for (X2, 0, 1, 0.25)
#debug concat(str(X2, 0, 2), " ")
#end
#debug concat("\nafter the loop I = ", str(I, 0, 0), "\n")
#declare K = 0;
#while (K < 3)
#debug concat("K=", str(K, 0, 0), " ")
#declare K = K + 1;
#end
#debug "\n"
#for (N, 1, 10)
#if (N = 4)
#break
#end
#debug concat(str(N, 0, 0), " ")
#end
#debug "\n"
1 2 3 4, 10 7 4, 0.00 0.25 0.50 0.75 1.00, after the loop I = 1 (10, 7, 4, then 1 fails the test), K=0 K=1 K=2 and 1 2 3.#switch, #case, #range
#switch (expr) evaluates its expression once. It must be followed directly by #case or #range (otherwise #switch not followed by #case or #range.). Each branch is closed by the next #case, #range, #else or #end; the whole construct is closed by one #end.
| Directive | The branch runs when |
|---|---|
#case (v) | the switch value equals v within 1e-10 |
#range (lo, hi) | the switch value is between lo and hi, both included |
#else | the default: no earlier branch matched |
#break | (not a branch) leaves the whole switch |
Without a #break, the code of a branch that has run goes on into the next branch (fall-through), including the default one. #case and #range outside a switch are an error (Mis-matched '#case' or '#range'.).
#macro Name(Val)
#switch (Val)
#case (1)
#debug "one\n"
#break
#case (2)
#debug "two\n"
#break
#range (3, 5)
#debug "three to five\n"
#break
#else
#debug "something else\n"
#end
#end
Name(1)
Name(2)
Name(4)
Name(9)
#switch (1)
#case (1)
#debug "falls "
#case (2)
#debug "through\n"
#end
one, two, three to five, something else and falls through.#end and its pairing
Every block directive needs an #end: #if, #ifdef, #ifndef (with their #elseif and #else branches), #while, #for, #switch and #macro. The parser keeps a stack of open constructs and an #end closes the top one. The stack is checked in these places:
| Message | Cause |
|---|---|
Mis-matched '#end'. | an #end with nothing open |
Mis-matched '#else'., Mis-matched '#elseif'. | the directive is not inside an #if, or (for #elseif) is in a #switch |
Mis-matched '#case' or '#range'. | the directive is not inside a #switch |
Invalid context for #break | a #break that is not inside a loop, a #case or a macro |
End of file reached but #end expected. | the main file ends with a construct open |
Unbalanced #end directives in include file. | an include file ends with a different number of open constructs than it began with. Open braces and parentheses give a warning (Unbalanced { in include file) |
#while loop did not end in file where it started., #for loop did not end in file where it started., #macro did not end in file where it started. | the construct was opened in one file and its #end is in another |
#switch not followed by #case or #range. | see #switch |
The checks are on text, not on meaning: a #end that is inside a skipped branch counts for the nesting only if it is a real directive (see the rules for skipped branches).
#fopen, #fclose, #read, #write
These directives read and write text and binary data files while the scene is parsed. #fopen binds an identifier to a file; the identifier always goes into the global table and its name must not be declared already.
| Directive | Meaning |
|---|---|
#fopen Id "name" read | opens an existing file for reading. The file is searched like an include file (the current directory and the library paths). A missing file is the error Cannot open user file name (read). |
#fopen Id "name" write | creates the file, or empties an existing one, for writing |
#fopen Id "name" append | opens the file for writing at its end (and creates it if it is not there) |
#fclose Id | closes the file and removes the identifier. Closing a file that is already closed is accepted |
Another directive on the same file inside a file directive (for instance a #read in the argument of a #write of the same file) is the error Can't nest directives accessing the same file. Writing to a file that is open for reading, or reading from one open for writing, gives an error that names the file.
#write
#write (Id, item, item ...) writes its items in order, with no separator between them. Items are tried in this way:
| Item | Written as |
|---|---|
a string expression (a literal, concat, str, chr, substr, vstr, strupr, strlwr, datetime, a string identifier) | the characters of the string, without quotes |
| a float | the number in C %g format, with no space after it (42, -7.25, 1.5) |
| a 2D vector | <1,2> followed by a space |
| a 3D vector | <1,2,3> followed by a space |
| a 4D vector | <1,2,3,4> followed by a space |
| a 5D vector (also a colour) | <1,2,3,4,5> followed by a space |
| a type word and a value (below) | binary integers, one per component of the value |
Each number is written with %g, so it has about six significant digits. A line end is written only if the text has one: use "\n". A string that is to be read back with #read must be written with its quotes ("\"text\"").
| Type word | Bytes | Byte order | Range |
|---|---|---|---|
uint8 | 1 | 0 to 255 | |
sint8 | 1 | -128 to 127 | |
uint16be, uint16le | 2 | big, little | 0 to 65535 |
sint16be, sint16le | 2 | big, little | -32768 to 32767 |
sint32be, sint32le | 4 | big, little | -2147483648 to 2147483647 |
A type word is followed by one value, which may be a vector of up to five components; each component is written as one integer of that type, rounded to the nearest integer, and a value outside the range is set to the nearest end of the range without a message. The next item starts a new value: uint16le 258, sint16be -2. There is no unsigned 32-bit type and no float type. The words are the same ones that appear in Reserved words.
#read
#read (Id, Name1, Name2 ...) reads one value for each name, in order. The file is read with the same tokenizer as the scene, so its text has the lexical form of the language (see Lexical structure): white space and comments between values are ignored, and one comma after a value is allowed and skipped. Three kinds of value can be read:
| In the file | The name becomes |
|---|---|
a float, with an optional + or - sign | a float |
<a, b> | a 2D vector (commas optional) |
<a, b, c> | a 3D vector |
<a, b, c, d> | a 4D vector |
<a, b, c, d, e> | a colour with five components (red, green, blue, filter, transmit) |
| a string literal in double quotes | a string |
Anything else is the error Expected float, vector, or string literal, with the position in the data file. A name that is not yet declared is declared with global scope; a name that exists is given the new value. Reading to the end of the data closes the file and removes its identifier, which is how a loop finds the end: #while (defined(Id)). A #read that finds no data left does not assign its names, so test them with defined.
#fopen Out "ex-data.txt" write
#write (Out, 42, "\n")
#write (Out, <1, 2, 3>, "\n")
#write (Out, "\"a string\"", "\n")
#write (Out, 1.5, " ", <1, 2>, " ", <1, 2, 3, 4>, " ", <1, 2, 3, 4, 5>, "\n")
#fclose Out
#fopen Out "ex-data.txt" append
#write (Out, -7.25, ", ", 8, "\n")
#fclose Out
#fopen In "ex-data.txt" read
#read (In, A1)
#read (In, B1)
#read (In, S1)
#read (In, F1, V2, V4, C5)
#read (In, N1, N2)
#debug concat("A1=", str(A1, 0, 0), " S1=", S1, " F1=", str(F1, 0, 1), " N1=", str(N1, 0, 2), " N2=", str(N2, 0, 0), "\n")
#debug concat("B1=", vstr(3, B1, ",", 0, 0), " V2=", vstr(2, V2, ",", 0, 0), " V4=", vstr(4, V4, ",", 0, 0), " C5=", vstr(5, C5, ",", 0, 0), "\n")
#debug concat("the file is closed after its last value: defined(In) = ", str(defined(In), 0, 0), "\n")
42, <1,2,3> , "a string", 1.5 <1,2> <1,2,3,4> <1,2,3,4,5> and -7.25, 8. The three #debug lines print the values read back and defined(In) = 0.#fopen Bin "ex-data.bin" write
#write (Bin, uint8 <65, 66, 67>)
#write (Bin, uint16le 258, sint16be -2)
#write (Bin, sint32le <1, 2>, uint8 300, sint8 -200)
#fclose Bin
41 42 43 02 01 ff fe 01 00 00 00 02 00 00 00 ff 80 in hexadecimal. The values 300 and -200 are cut to 255 and -128.#debug, #warning, #error, #render, #statistics
Each takes one string expression, written directly after the directive word (no parentheses are needed).
| Directive | Effect | Long text |
|---|---|---|
#debug s | writes s to the debug stream, with no line end added | more than 200 characters: the first 156 and ... are written |
#warning s | writes a warning that names the file, line and column; the parse goes on | more than 160 characters: the first 124 and ... |
#error s | stops the parse with Parse halted by #error directive: s | as #warning |
#render s | gives the warning #render and #statistics streams are no longer available. Redirecting output to #debug stream. and then acts as #debug | as #debug |
#statistics s | the same as #render | as #debug |
The front end has five message streams (debug, fatal, render, statistics and warning) and can show or hide each of them: the +GA option turns all of them on, and with -GA the text of a parse error is not shown. The render and statistics streams are no longer separate; the directives that named them write to the debug stream. A directive in a skipped branch does nothing.
#warning "this is a warning"
#debug "debug text\n"
Parse Warning: this is a warning with the file, line and column, and the second prints debug text.#error "stopped here"
Parse Error: Parse halted by #error directive: stopped here
Fatal error in parser: Cannot parse input.
Not described
Known, not yet covered
- Reference: the
#fopenoutput file name and directory when the name has no path, and the I/O restrictions of the program (the run here had them disabled). - Reference: the exact list of library paths that the front end adds on its own (the scene file's directory, the install directory); only the current directory and the
+Lpaths were observed.