#LyX 2.4 created this file. For more info see https://www.lyx.org/ \lyxformat 620 \begin_document \begin_header \save_transient_properties true \origin unavailable \textclass scrbook \begin_preamble % Added by lyx2lyx \setlength{\parskip}{\medskipamount} \setlength{\parindent}{0pt} \end_preamble \use_default_options false \maintain_unincluded_children no \language american \language_package default \inputencoding iso8859-1 \fontencoding auto \font_roman "times" "default" \font_sans "helvet" "default" \font_typewriter "courier" "default" \font_math "auto" "auto" \font_default_family default \use_non_tex_fonts false \font_sc false \font_roman_osf false \font_sans_osf false \font_typewriter_osf false \font_sf_scale 100 100 \font_tt_scale 100 100 \use_microtype false \use_dash_ligatures true \graphics dvips \default_output_format default \output_sync 0 \bibtex_command default \index_command default \float_placement htb \paperfontsize 12 \spacing single \use_hyperref false \papersize letter \use_geometry true \use_package amsmath 1 \use_package amssymb 1 \use_package cancel 1 \use_package esint 0 \use_package mathdots 0 \use_package mathtools 1 \use_package mhchem 0 \use_package stackrel 1 \use_package stmaryrd 1 \use_package undertilde 1 \cite_engine basic \cite_engine_type default \biblio_style plain \use_bibtopic false \use_indices false \paperorientation portrait \suppress_date false \justification true \use_refstyle 0 \use_formatted_ref 0 \use_minted 0 \use_lineno 0 \index Index \shortcut idx \color #008000 \end_index \leftmargin 1in \topmargin 1in \rightmargin 0.5in \bottommargin 1in \secnumdepth 2 \tocdepth 2 \paragraph_separation indent \paragraph_indentation default \is_math_indent 0 \math_numbering_side default \quotes_style english \dynamic_quotes 0 \papercolumns 1 \papersides 2 \paperpagestyle headings \tablestyle default \tracking_changes false \output_changes false \change_bars false \postpone_fragile_content false \html_math_output 0 \html_css_as_file 0 \html_be_strict false \docbook_table_output 0 \docbook_mathml_prefix 1 \end_header \begin_body \begin_layout Title The Ruamoko Programming Language \end_layout \begin_layout Author Bill Currie \begin_inset Formula $\bullet$ \end_inset Jeff Teunissen \end_layout \begin_layout Publishers QuakeForge Press \end_layout \begin_layout Uppertitleback This manual is free; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. \begin_inset Newline newline \end_inset \begin_inset Newline newline \end_inset This manual is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. \begin_inset Newline newline \end_inset \begin_inset Newline newline \end_inset You should have received a copy of the GNU General Public License along with this manual: if not, write to: \begin_inset Newline newline \end_inset \begin_inset Newline newline \end_inset Free Software Foundation, Inc. \begin_inset Newline newline \end_inset 59 Temple Place - Suite 330 \begin_inset Newline newline \end_inset Boston MA 02111-1307 \begin_inset Newline newline \end_inset USA \end_layout \begin_layout Lowertitleback Copyright © 2002-2003 Bill Currie and Jeff Teunissen \end_layout \begin_layout Standard \begin_inset CommandInset toc LatexCommand tableofcontents \end_inset \end_layout \begin_layout Addchap Preface \end_layout \begin_layout Standard In December 1996, Id Software released \emph on Quake \emph default to the world. It's doubtful that they knew at the time that it would spark a revolution – but such a revolution happened. To the game industry's surprise, people were getting the game not just to play it, but to \emph on change \emph default it\SpecialChar endofsentence For the first time, people could make whole new games based on the Quake engine without having to rewrite the whole game – and in fact you couldn't rewrite the whole game, because the main source code wasn't available to the general public. What \series bold was \series default available was something new – the game wasn't just a game, it was a virtual machine that had a byte-code instruction set – and it had a compiler that you could use to make new games to run inside that engine. The language (called \emph on QuakeC \emph default ) was kind of crude, and the compiler was even more crude – but it was a revolutionary development. \end_layout \begin_layout Standard Now, let's fast-forward to another December – this time, three years later. In another revolutionary move, Id Software released the source code to the complete Quake engine. This gave many people the opportunity to do a lot more than just make \begin_inset Quotes eld \end_inset mods \begin_inset Quotes erd \end_inset for Quake. Instead, people could make all-new games without using Quake itself. Many projects started up around this source code, with many aims\SpecialChar ldots but one project grew to be the most dominant: That project is \emph on QuakeForge \emph default . \end_layout \begin_layout Standard QuakeForge has developed a number of interesting things involving the Quake engine, but most of them are beyond the scope of this manual. This manual documents the \emph on Ruamoko \begin_inset Foot status collapsed \begin_layout Plain Layout The name Ruamoko comes from the Maori name for their god of volcanoes and earthquakes. According to myth, Ruamoko is not yet born, and when he shakes inside the Earth-mother, the world trembles. \end_layout \end_inset \emph default language, a language based on Id Software's QuakeC, but which has been expanded in ways far beyond the original language. \end_layout \begin_layout Standard The idea behind this book is to give new programmers a solid foundation in both of the programming models (procedural and object-oriented) supported by the Ruamoko language, while giving experienced Ruamoko programmers a complete reference for development of game code. \end_layout \begin_layout Standard \begin_inset FloatList figure \end_inset \end_layout \begin_layout Part Classical Programming in Ruamoko \end_layout \begin_layout Chapter \begin_inset CommandInset label LatexCommand label name "cha:A-Tutorial-Introduction" \end_inset Introduction: Foot, Meet Mister Rocket Launcher \end_layout \begin_layout Standard Let us begin with a quick introduction to Ruamoko. Our aim here is to show the basic elements of the language in real programs, but without getting bogged down in details or rules. At this point, we're not even trying to be complete, or even precise (except that the examples are meant to be correct). We want to get you as quickly as possible to the point where you can write useful programs, and to do that we have to concentrate on the basics: variables and constants, arithmetic, flow control, functions, and the rudiments of input and output. We are intentionally leaving out of this chapter features of Ruamoko that are important for writing bigger programs, or programs to run in an actual Quake engine. These include entities, structures, pointers, most of the operators, objects, and the standard builtin library. \end_layout \begin_layout Standard This approach has its drawbacks. Most notable is that the complete story on any particular language feature is not found here, and the brief tutorial, just by being brief, may be misleading. And because the examples don't use the full power of Ruamoko, they may not be as elegant or concise as they could be; we \series bold have \series default tried to minimize these effects, but be warned. Another drawback is that later chapters will repeat some of what's presented here. We hope that the repetition will help more than it annoys. \end_layout \begin_layout Standard In any case, experienced programmers should be able to get an idea, from this chapter, of some of the things that can be done in Ruamoko, for their own needs. Beginners should supplement it by writing small, similar programs of their own. Both groups can use it as a framework on which to hang the more detailed descriptions that begin in later chapters. \end_layout \begin_layout Section Getting Started \end_layout \begin_layout Standard The best way to learn a new programming language is by writing programs in it. The first program one writes is almost always the same for all new languages: print the phrase \begin_inset Quotes eld \end_inset Hello, world! \begin_inset Quotes erd \end_inset on the screen. \end_layout \begin_layout Standard This is the big hurdle. To get past it, you have to be able to create the program text somewhere, compile it, load it successfully, load it, run it, and find out where the output went. With these mechanical details mastered, everything else is relatively easy. \end_layout \begin_layout Standard \begin_inset Float figure placement document alignment document wide false sideways false status collapsed \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \begin_inset ERT status collapsed \begin_layout Plain Layout \backslash vspace{-1 \backslash parskip} \end_layout \begin_layout Plain Layout \end_layout \end_inset \end_layout \begin_layout LyX-Code \begin_inset CommandInset include LatexCommand verbatiminput filename "hello.r" literal "true" \end_inset \end_layout \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption Standard \begin_layout Plain Layout \begin_inset CommandInset label LatexCommand label name "cap:Hello-World" \end_inset \begin_inset Quotes eld \end_inset Hello World \begin_inset Quotes erd \end_inset \end_layout \end_inset \end_layout \end_inset A Ruamoko program that does this simple task is found in Figure \begin_inset CommandInset ref LatexCommand vref reference "cap:Hello-World" nolink "false" \end_inset . To run this program, you first have to compile it. To compile it, you need to save the source code into a file (for example, \family typewriter hello.r \family default ), then compile it with the command \family typewriter \series bold qfcc -o qwaq.dat hello.r \family default \series default . \end_layout \begin_layout Standard If you haven't screwed anything up, such as omitting a character or misspelling something, the compilation will proceed. You should be rewarded with something that looks something like Figure \begin_inset CommandInset ref LatexCommand vref reference "cap:qfcc-output" nolink "false" \end_inset . \begin_inset Float figure placement document alignment document wide false sideways false status collapsed \begin_layout LyX-Code \begin_inset CommandInset include LatexCommand verbatiminput filename "qfcc-output.txt" literal "true" \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption Standard \begin_layout Plain Layout \family typewriter \begin_inset CommandInset label LatexCommand label name "cap:qfcc-output" \end_inset \series bold qfcc \family default \series default output \end_layout \end_inset \end_layout \end_inset \end_layout \begin_layout Standard You run \family typewriter qwaq.dat \family default by issuing the command \family typewriter \series bold qwaq \family default \series default . The program should print \begin_inset Quotes eld \end_inset \family typewriter Hello, world! \family default \begin_inset Quotes erd \end_inset to your screen. \end_layout \begin_layout Standard Now, for some explanations regarding the program itself. All Ruamoko programs, regardless of size, consist mainly of \emph on functions \emph default and \emph on variables \emph default . A function contains statements that tell the compiler what computing operations you want to do, and variables store values used during the operation of the program. Ruamoko functions are roughly equivalent to C's functions, or Pascal's procedures and functions. Our example is a function called \family typewriter main \family default . You can create functions with just about any name you like, but \begin_inset Quotes eld \end_inset \family typewriter main \family default \begin_inset Quotes erd \end_inset is special – program execution begins there \begin_inset Foot status collapsed \begin_layout Plain Layout This is not precisely true. When used in a game engine, there are certain other functions that are called by the engine during the course of a game. \end_layout \end_inset . This means that every program must have a \family typewriter main \family default function somewhere. \end_layout \begin_layout Standard The main function will usually call other functions to do its job – some of them you write, and some of them are provided by the virtual machine your program runs inside. The first lines of the program (the ones beginning with \begin_inset Quotes eld \end_inset \family typewriter #include \family default \begin_inset Quotes erd \end_inset ) tell the compiler to include information about the standard variables, constants, \emph on fields \emph default \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout fields \end_layout \end_inset , and \emph on engine functions \begin_inset Foot status collapsed \begin_layout Plain Layout also known as \emph on builtins \emph default . \end_layout \end_inset \emph default \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout functions, engine \end_layout \end_inset provided by the environment \begin_inset Foot status collapsed \begin_layout Plain Layout The environment will be described later. \end_layout \end_inset . \end_layout \begin_layout Standard One way of communicating data between functions is for the calling function to provide a list of values, called \emph on arguments \emph default \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout arguments \end_layout \end_inset , to the function it calls. The parentheses after the function's name surround the \emph on argument list \emph default \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout argument list \end_layout \end_inset . In this example, main is defined to be a function that expects no arguments, which is indicated by an empty list: \begin_inset space ~ \end_inset \family typewriter () \family default . \end_layout \begin_layout Standard The statements of a function are enclosed in curly braces, \begin_inset space ~ \end_inset \family typewriter {} \family default . The function \family typewriter main \family default contains only one statement, \family typewriter printf ("Hello, world! \backslash n") \family default . This is a \emph on function call \emph default , which transfers control from one function to another. A function is called by giving its name, followed by a list of arguments enclosed by parentheses, so this calls the function \family typewriter printf \family default with the argument \family typewriter "Hello, world! \backslash n" \family default . \family typewriter printf \family default is an engine function that prints output, in this case the string of characters between the quotes. \end_layout \begin_layout Standard A sequence of characters between double quotes, like \family typewriter "Hello, world! \backslash n" \family default , is called a \emph on string constant \emph default or simply a \emph on string \emph default . For the moment, our only use of strings will be as arguments for \family typewriter printf \family default and other functions. \end_layout \begin_layout Standard The sequence \family typewriter \backslash n \family default in the string is Ruamoko notation for the \emph on newline character \emph default , which when printed tells the terminal (or a game client) to advance to the next line in the output. If you leave out the \family typewriter \backslash n \family default , you will find that there is no advance after the character string is printed. You must use \family typewriter \backslash n \family default to include a newline character in the printf argument; if you try to insert a newline yourself into the string, the Ruamoko compiler will give you an error message when you compile the program. \end_layout \begin_layout Standard \begin_inset Float figure placement document alignment document wide false sideways false status collapsed \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \begin_inset ERT status collapsed \begin_layout Plain Layout \backslash vspace{-1 \backslash parskip} \end_layout \begin_layout Plain Layout \end_layout \end_inset \end_layout \begin_layout LyX-Code \begin_inset CommandInset include LatexCommand verbatiminput filename "hello2.r" literal "true" \end_inset \end_layout \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption Standard \begin_layout Plain Layout \begin_inset CommandInset label LatexCommand label name "cap:A-different-Hello" \end_inset A different \begin_inset Quotes eld \end_inset Hello World \begin_inset Quotes erd \end_inset \end_layout \end_inset \end_layout \end_inset The \family typewriter printf() \family default function never supplies a newline automatically, so several calls may be used to build up an output line in stages. Our first program could just as easily been written as it is in figure \begin_inset CommandInset ref LatexCommand vref reference "cap:A-different-Hello" nolink "false" \end_inset , and it would have produced identical output. \end_layout \begin_layout Standard Note that \family typewriter \backslash n \family default represents only a single character. An \emph on escape character \emph default like \family typewriter \backslash n \family default gives you a general way to express hard-to-type or invisible characters. Among the others are \family typewriter \backslash t \family default for a tab, \family typewriter \backslash b \family default for a backspace, \family typewriter \backslash " \family default for a double-quote, and \family typewriter \backslash \backslash \family default for the backslash character itself. There is a complete list in [section] \end_layout \begin_layout Section Variables and Mathematical Expressions \end_layout \begin_layout Standard \begin_inset Float figure placement document alignment document wide false sideways false status collapsed \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \begin_inset ERT status collapsed \begin_layout Plain Layout \backslash vspace{-1 \backslash parskip} \end_layout \begin_layout Plain Layout \end_layout \end_inset \end_layout \begin_layout LyX-Code \begin_inset CommandInset include LatexCommand verbatiminput filename "radians.r" literal "true" \end_inset \end_layout \begin_layout Plain Layout \noindent \begin_inset CommandInset line LatexCommand rule offset "0.5ex" width "100line%" height "1pt" \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption Standard \begin_layout Plain Layout \begin_inset CommandInset label LatexCommand label name "cap:Degrees-to-radians" \end_inset Degrees to radians \end_layout \end_inset \end_layout \end_inset In figure \begin_inset CommandInset ref LatexCommand vref reference "cap:Degrees-to-radians" nolink "false" \end_inset , we find a simple program uses the formula \begin_inset Formula $R=D\,\times\,(\frac{\pi}{180})$ \end_inset to print a table of various angles in both their degrees and radian equivalents. \end_layout \begin_layout Standard The line \begin_inset Quotes eld \end_inset \family typewriter /* Print a silly conversion table between degrees and radians */ \family default \begin_inset Quotes erd \end_inset and the three parts that say things like \begin_inset Quotes eld \end_inset \family typewriter // lower limit \family default \begin_inset Quotes erd \end_inset are \emph on comments \emph default \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout comments \end_layout \end_inset . Characters between \family typewriter /* \family default and \family typewriter */ \family default , and anything between \family typewriter // \family default and the next line, are ignored by the compiler; they may be used freely to make a program easier for humans to understand. Comments may appear anywhere a blank space, or a tab, or a newline can. \end_layout \begin_layout Standard In Ruamoko, all variables must be declared before they are used., usually at the beginning of the function before any statements. A declaration \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout declaration, variable \end_layout \end_inset announces the properties of variables to the compiler; it consists of a type name and a list of one or more variables, such as \end_layout \begin_layout LyX-Code float degrees, radians; \begin_inset Newline newline \end_inset integer lower, upper, step; \end_layout \begin_layout Standard The type \family typewriter float \family default means that the \family typewriter degrees \family default and \family typewriter radians \family default variables are floating-point numbers (numbers that can have a fractional part), and the type \family typewriter integer \family default means that the \family typewriter lower \family default , \family typewriter upper \family default , and \family typewriter step \family default variables are integers – that is, they are whole numbers. \end_layout \begin_layout Standard Unlike C, in which \family typewriter int \family default and \family typewriter float \family default can have different sizes depending on the machine, Ruamoko variables always have a size that is a multiple of 4 bytes (32 bits). \end_layout \begin_layout Standard Ruamoko provides four basic data types \begin_inset Index idx range none pageformat default status collapsed \begin_layout Plain Layout types, basic \end_layout \end_inset : \end_layout \begin_layout Standard \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout \family typewriter float \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout floating-point numbers \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family typewriter integer \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none whole numbers, with a range between -2147483648 and 2147483647. \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family typewriter string \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none text strings \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family typewriter vector \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none three-dimensional floating-point vectors \end_layout \end_inset \end_inset \end_layout \begin_layout Standard There are more types than just these four, but this is the list of \emph on basic types \emph default . There are also \emph on arrays \emph default , \emph on structures \emph default , and \emph on unions \emph default of these basic types, \emph on pointers \emph default to them, and functions that return them, all of which we'll meet later. \end_layout \begin_layout Standard The computation in the conversion program begins with the assignment statements \end_layout \begin_layout LyX-Code lower = 0; \begin_inset Newline newline \end_inset upper = 360; \begin_inset Newline newline \end_inset step = 45; \end_layout \begin_layout Standard which set the variables to their initial values. In Ruamoko, as in C, a statement is terminated by the semicolon character. \end_layout \begin_layout Standard Each line of the table is computed in the same manner, so we use a loop that repeats once per output line; this is the purpose of the \family typewriter while \family default loop \end_layout \begin_layout LyX-Code while (degrees <= upper) { \begin_inset Newline newline \end_inset \begin_inset Formula $\vdots$ \end_inset \begin_inset Newline newline \end_inset } \end_layout \begin_layout Standard The \family typewriter while \family default loop works like this: The condition in parentheses is tested. If it is true (if \family typewriter degrees \family default is less than or equal to \family typewriter upper \family default ), the body of the loop (the three statements enclosed in the block delimited by the curly braces) is executed. Then the condition is tested again, and if it's true again, the body is executed again. If and when the condition becomes false ( \family typewriter degrees \family default exceeds \family typewriter upper \family default ), the loop ends and execution continues at the statement following the loop's end. Since there are no more statements in the program, the end of the loop terminates the program. \end_layout \begin_layout Standard The body of a while loop can be one or more statements enclosed in braces (called a block, or compound statement), or a single statement without braces, as in \end_layout \begin_layout LyX-Code while (i < n) \begin_inset Newline newline \end_inset i = i * 2; \end_layout \begin_layout Standard In either case, we will always indent the statements controlled by the while by one tab stop (which we will show as four spaces), so you can see at a glance which statements are inside the loop. The indentation emphasizes the logical structure of the program. The compiler does not care how your program looks, but proper indentation and spacing are critical in making programs easy for people (including you) to read. We recommend writing only one statement per line, and using blanks around operators to make groupings clear. The positions of braces is less important, though you should be warned that many programmers have passionate beliefs about how braces should be used. We have chosen the so-called \begin_inset Quotes eld \end_inset One True Brace Style \begin_inset Quotes erd \end_inset , which is the style that Brian Kernighan and Dennis Ritchie used in their book \bar under The C Programming Language \bar default , for consistency. Pick a style that suits you, and use it consistently in your own work, but be prepared to adapt to the styles of other programmers when writing as a group. \end_layout \begin_layout Standard Most of the work gets done inside the loop. The radians for the angle are computed and assigned to the \family typewriter radians \family default variable using the statement \end_layout \begin_layout LyX-Code radians = degrees * (PI / 180); \end_layout \begin_layout Standard This example also shows a bit more of how \family typewriter printf() \family default works. \family typewriter printf() \family default is a general-purpose output formatting function, which we will describe in detail in [chapter]. Its first argument is a string to be printed, with each \family typewriter % \family default indicating where one of the other (second, third, and so on) arguments is to be substituted, and in what form it is to be output. For instance, \family typewriter %f \family default specifies a \family typewriter float \family default argument, so the statement \end_layout \begin_layout LyX-Code printf("%f \backslash t%f \backslash n", degrees, radians); \end_layout \begin_layout Standard causes the values of the two \family typewriter float \family default variables \family typewriter degrees \family default and \family typewriter radians \family default to be printed, with a tab ( \family typewriter \backslash t \family default ) between them. \end_layout \begin_layout Chapter Types, Operators, and Expressions \end_layout \begin_layout Standard Variables and constants are the basic data units manipulated in a program. Declarations list the variables to be used, and state what type they have and perhaps what the initial values for them are. Operators specify what is to be done to them. Expressions combine variables and constants to produce new values. The type of a unit determines the set of values it can have and what operations are permissible for it. These building blocks are the subject of this chapter. \end_layout \begin_layout Section Variable Names \end_layout \begin_layout Standard Though we didn't say it in Chapter \begin_inset CommandInset ref LatexCommand ref reference "cha:A-Tutorial-Introduction" nolink "false" \end_inset , there are some restrictions on variable names and symbolic constants. Names are composed of letters and digits; the first character must be a letter (the underscore, \begin_inset Quotes eld \end_inset _ \begin_inset Quotes erd \end_inset , counts as a letter – it's often useful for improving the readability of long names). Don't begin variable names with an underscore, however, since functions beginning with _ are reserved for library and engine functions. Upper-case and lower-case are distinct, so x and X are two different names. Traditional practice is to use lower-case or mixed case for variable names, and all upper-case for \emph on symbolic constants \emph default , also known as \emph on defines \emph default . Keywords like if, else, integer, float, etc. are reserved – you can't use them as variable names. \end_layout \begin_layout Section Constants \end_layout \begin_layout Standard An integer constant like \family typewriter 5678 \family default is an integer. Floating-point constants contain a decimal point ( \family typewriter 123.4 \family default ) or an exponent ( \family typewriter 1e-2 \family default ) or both ( \family typewriter 1.2e3 \family default ). \end_layout \begin_layout Standard The value of an integer can be specified in octal (base 8, 0 \begin_inset Formula $\ldots$ \end_inset 7) or hexadecimal (base 16, 0 \begin_inset Formula $\ldots$ \end_inset F, hereafter called \begin_inset Quotes eld \end_inset hex \begin_inset Quotes erd \end_inset ) instead of decimal. A leading \family typewriter 0 \family default (zero) on an integer constant means octal; a leading \family typewriter 0x \family default or \family typewriter 0X \family default means hex. For example, decimal 31 can be written as \family typewriter 037 \family default in octal, or \family typewriter 0x1f \family default or \family typewriter 0X1F \family default in hex. \end_layout \begin_layout Standard Certain characters can be represented in string constants by escape sequences like \family typewriter \backslash n \family default (newline); these sequences look like two characters, but represent only one. In addition, an arbitrary byte value can be represented by \end_layout \begin_layout LyX-Code \backslash o \end_layout \begin_layout Standard where \family typewriter o \family default is one to three octal digits or by \end_layout \begin_layout LyX-Code \backslash xh \end_layout \begin_layout Standard where \family typewriter h \family default is one or more hex digits. So we might write \end_layout \begin_layout LyX-Code "vtab = \backslash 013" \end_layout \begin_layout Standard or, in hex, \end_layout \begin_layout LyX-Code "vtab = \backslash x0b" \end_layout \begin_layout Standard The complete set of escape sequences is found in Table \begin_inset CommandInset ref LatexCommand ref reference "cap:Escape-sequences" nolink "false" \end_inset . \end_layout \begin_layout Standard \begin_inset Float table placement document alignment document wide false sideways false status collapsed \begin_layout Plain Layout \begin_inset space \hfill{} \end_inset \begin_inset Tabular \begin_inset Text \begin_layout Plain Layout Sequence \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Description \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash a \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout Alert (bell) character \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash b \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout backspace \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash f \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout form feed \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash n \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout newline \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash r \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout carriage return \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash t \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout tab character \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash \backslash \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout backslash \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash ? \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout question mark \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash ' \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout single quote \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash " \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout double quote \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash ooo \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout octal number \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash xhh \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout hex number \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout \backslash ^ \end_layout \end_inset \begin_inset Text \begin_layout Plain Layout alternate character set (toggles) \end_layout \end_inset \end_inset \begin_inset space \hfill{} \end_inset \end_layout \begin_layout Plain Layout \begin_inset Caption Standard \begin_layout Plain Layout \begin_inset CommandInset label LatexCommand label name "cap:Escape-sequences" \end_inset Escape sequences \end_layout \end_inset \end_layout \end_inset \end_layout \begin_layout Chapter Control Constructs: Kneel Before Zod \end_layout \begin_layout Chapter Arrays and Pointers: Pull Pin, Then Throw \bar under GRENADE \end_layout \begin_layout Chapter Breaking Up The Program: Now Where Did I Put That? \end_layout \begin_layout Part Object-Oriented Programming in Ruamoko \end_layout \begin_layout Part Language Reference \end_layout \begin_layout Chapter Types \end_layout \begin_layout Standard This is currently just new stuff in \family typewriter \series bold qfcc \family default \series default . \end_layout \begin_layout Section New Type Features \end_layout \begin_layout Subsection New Types \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter integer \family default 32 bit signed integer \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter id \family default generic object pointer \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter Class \family default class object pointer \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter Protocol \family default protocol object pointer \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter Method \family default method pointer \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter SEL \family default selector \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter IMP \family default message implementation \end_layout \begin_layout Standard \family typewriter id \family default , \family typewriter Class \family default , \family typewriter Protocol \family default , \family typewriter Method \family default , \family typewriter SEL \family default and \family typewriter IMP \family default are part of \family typewriter \series bold qfcc \family default \series default 's Objective-QC extensions. \end_layout \begin_layout Subsection Enumerators \end_layout \begin_layout Standard as per C \end_layout \begin_layout Subsection Structures \end_layout \begin_layout LyX-Code struct foo { \begin_inset Newline newline \end_inset integer bar; \begin_inset Newline newline \end_inset float baz; \begin_inset Newline newline \end_inset void () func; \begin_inset Newline newline \end_inset }; \end_layout \begin_layout Standard Structures with no elements can be declared for making opaque types (particularly useful for engine interface functions). \end_layout \begin_layout Subsection Arrays \end_layout \begin_layout LyX-Code integer [13] array; \end_layout \begin_layout Subsection Pointers \end_layout \begin_layout Standard Pointers are declared the same way as arrays, but with no number in the \family typewriter [] \family default s. In fact, arrays are just pointers with limited (compile-time) bounds checking (constant indices). \end_layout \begin_layout Subsection Complex types \end_layout \begin_layout Standard Complex types can be created by nesting type declarations within \family typewriter () \family default s. e.g.: \end_layout \begin_layout LyX-Code (.float) (string name) find_field; \end_layout \begin_layout Standard declares a function ( \family typewriter find_field \family default ) taking a string parameter and returning a float field `offset'. Without the \family typewriter () \family default s around the \family typewriter .float \family default , the declaration would be a function field. \end_layout \begin_layout Subsection \family typewriter typedef \end_layout \begin_layout Standard By using \family typewriter typedef \family default complex types can be given symbolic names. e.g.: \end_layout \begin_layout LyX-Code struct foo_s {}; \begin_inset Newline newline \end_inset typedef foo_s [] foo_t; \end_layout \begin_layout Standard creates type \family typewriter foo_t \family default which is a pointer to the structure \family typewriter foo_s \family default (which happens to be opaque). \end_layout \begin_layout Subsection Variable-argument functions \end_layout \begin_layout Standard Typed parameters preceding the ellipsis are allowed, e.g.: \family typewriter void (string fmt, \SpecialChar ldots ) printf; \end_layout \begin_layout Standard More importantly, it is now possible to write vararg functions in QC. \family typewriter @argc \family default gives the number of parameters passed through the ellipsis and \family typewriter @argv \family default is an array of vectors representing the parameters passed through \family typewriter \SpecialChar ldots \family default . \end_layout \begin_layout Standard \series bold \emph on Warning: attempting to pass \series default \emph default \family typewriter \series bold \emph on @argv \family default \series default \emph default \series bold \emph on to a non-engine function will not work. This is because of changes in how local variables are handled by the compiler. \end_layout \begin_layout Subsection Improved type checking \end_layout \begin_layout Standard Function parameters and return types are are fully checked, including the number of parameters passed to a function. Functions with different return types and/or different parameter types or counts are distinct types and mixing them up will cause a type mismatch error. Similar for pointers to various types. \end_layout \begin_layout Chapter Variables \end_layout \begin_layout Section Local variables \end_layout \begin_layout Subsubsection Initialization \end_layout \begin_layout Standard Local variables of basic types can now be initialized when declared. e,g, \end_layout \begin_layout Verse \family typewriter local integer elite = 31337; \end_layout \begin_layout Subsubsection Unused variables \end_layout \begin_layout Standard Local variables that are declared but not used produce a warning. \end_layout \begin_layout Subsubsection Uninitialized variables \end_layout \begin_layout Standard Checks are done to ensure that local variables have been initialized before being used. However, these checks are not perfect and false positives are very likely in complex code. Occurrences of false negatives are not known, but the possibility of their existence remains and any examples of false negatives should be reported as bugs. \end_layout \begin_layout Section Complex global variables \end_layout \begin_layout Standard Global array variables can be initialized using \family typewriter = { \family default \family typewriter \emph on element-list \family default \emph default \family typewriter }; \family default . Element lists may be nested using \family typewriter {} \family default . Structures cannot currently be initialized, but this is a FIXME :) \end_layout \begin_layout Section Magic variables \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @self \family default Automagically-declared entity variable the engine will use for \family typewriter touch \family default and \family typewriter think \family default functions. This allows \family typewriter self \family default to be used as the object hidden parameter in methods. \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @this \family default Automagically-declared \family typewriter id \family default field that the engine expects to point to the object associated with the entity. The engine will use this field, if it exists, to set the \family typewriter self \family default parameter to \family typewriter touch \family default and \family typewriter think \family default methods (the engine assumes it's calling a method rather than a function if the @this field is used. \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @argc \family default Number of parameters passed through \family typewriter \SpecialChar ldots \family default in vararg functions. Not valid elsewhere. \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @argv \family default Array of vectors representing the parameters passed through \family typewriter \SpecialChar ldots \family default in vararg functions. Not valid elsewhere. \end_layout \begin_layout Chapter Code constructs \end_layout \begin_layout Section \family typewriter break \end_layout \begin_layout Standard The \family typewriter break \family default statement can be used to leave a loop ( \family typewriter while \family default , \family typewriter do \family default \SpecialChar ldots \family typewriter while \family default , or \family typewriter for \family default ) prematurely. The \family typewriter break \family default statement is also used to leave a \family typewriter switch \family default statement. \end_layout \begin_layout Section \family typewriter continue \end_layout \begin_layout Standard The \family typewriter continue \family default statement is used to jump to the beginning of a loop. In \family typewriter for \family default loops, the test and post expressions are evaluated before continuing with the loop. \end_layout \begin_layout Section \family typewriter for \end_layout \begin_layout Standard The \family typewriter for \family default loop is: \end_layout \begin_layout LyX-Code for ( \emph on initialization-expression \emph default ; \emph on test-expression \emph default ; \emph on post-expression \emph default ) \end_layout \begin_layout LyX-Code \emph on statement \end_layout \begin_layout Standard and is equivalent to \end_layout \begin_layout LyX-Code \emph on initialization expression \end_layout \begin_layout LyX-Code while ( \emph on test expression \emph default ) { \end_layout \begin_layout LyX-Code \emph on statement \end_layout \begin_layout LyX-Code \emph on post expression \end_layout \begin_layout LyX-Code } \end_layout \begin_layout Section \family typewriter switch \end_layout \begin_layout Standard The \family typewriter switch \family default statement is used to select between multiple code blocks based on the value of an expression. \end_layout \begin_layout LyX-Code switch ( \emph on test expression \emph default ) { \begin_inset Newline newline \end_inset case \emph on value \emph default : \begin_inset Newline newline \end_inset \emph on optional statements \begin_inset Newline newline \end_inset \emph default case \emph on value \emph default : \begin_inset Newline newline \end_inset \emph on optional statements \emph default \begin_inset Newline newline \end_inset default: \begin_inset Newline newline \end_inset \emph on optional statements \emph default \begin_inset Newline newline \end_inset } \end_layout \begin_layout Standard Code execution starts at the selected \family typewriter case \family default and continues on to the end of the switch block. Following \family typewriter case \family default s do \emph on not \emph default affect code execution. If this behavior is not desired, as is usual, then a \family typewriter break \family default statement is required to cause the code to jump to the end of the \family typewriter switch \family default , skipping any intervening code. That is, just like C. \end_layout \begin_layout Subsubsection \family typewriter \emph on test expression \end_layout \begin_layout Standard The test expression may result in a float, string or integer value. \end_layout \begin_layout Subsubsection \family typewriter case \family default \family typewriter \emph on value \end_layout \begin_layout Verse \family typewriter case \family default \family typewriter \emph on value \emph default : \end_layout \begin_layout Standard The case value may be of any constant type consistent with the test expression of the \family typewriter switch \family default . \end_layout \begin_layout Subsubsection \family typewriter default \end_layout \begin_layout Standard If specified, this is where execution will go when no \family typewriter case \family default has been selected by the test expression. If not specified, and no \family typewriter case \family default has been selected by the test expression, the \family typewriter switch \family default does not execute any code within the block. \end_layout \begin_layout Section Expressions \end_layout \begin_layout Subsection Binary \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter << \begin_inset space ~ \end_inset >> \family default bit shift left and right \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter ^ \family default bitwise exclusive or \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter % \family default modulus \end_layout \begin_layout Subsubsection Assignment \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter \emph on op \emph default = \family default equivalent to \family typewriter a = a \family default \family typewriter \emph on op \family default \emph default \family typewriter b \family default . \end_layout \begin_layout Subsection Unary \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter ~ \family default bitwise not \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter & \family default address \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter ++ \emph on e \emph default \begin_inset space ~ \end_inset -- \emph on e \family default \emph default pre-increment and decrement \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter \emph on e \emph default ++ \begin_inset space ~ \end_inset \emph on e \emph default -- \family default post-increment and decrement \end_layout \begin_layout Subsection Other \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter \emph on type \begin_inset space ~ \end_inset \emph default ( \emph on expr \emph default ) \family default cast expression. Works only for converting between integer and float types and between pointer types. \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter \emph on expr \emph default [ \emph on expr \emph default ] \family default array indexing. \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter \emph on expr \emph default ? \emph on expr \emph default : \emph on expr \family default \emph default C's trinary expression \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter [ \emph on expr \emph default \begin_inset space ~ \end_inset \emph on exprs \emph default ] \family default Objective-QC message \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @selector( \emph on exprs \emph default ) \family default Objective-QC selector expression \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @protocol( \emph on name \emph default ) \family default Objective-QC protocol expression \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @encode( \emph on type \emph default ) \family default Objective-QC type encoding expression \end_layout \begin_layout Labeling \labelwidthstring 00.00.0000 \family typewriter @ \emph on string \family default \emph default Objective-QC string object. Currently identical to a normal QC string. \end_layout \begin_layout Standard \begin_inset CommandInset index_print LatexCommand printindex type "idx" name "Index" literal "true" \end_inset \end_layout \end_body \end_document