Fetching contributors…
Cannot retrieve contributors at this time
131 lines (88 sloc) 9.65 KB
\section{What is Haxe?}
\todo{Could we have a big Haxe logo in the First Manual Page (Introduction) under the menu (a bit like a book cover ?) It looks a bit empty now and is a landing page for "Manual"}
Haxe consists of a high-level, open source programming language and a compiler. It allows compilation of programs, written using an ECMAScript\footnote{}-oriented syntax, to multiple target languages. Employing proper abstraction, it is possible to maintain a single code-base which compiles to multiple targets.
Haxe is strongly typed but the typing system can be subverted where required. Utilizing type information, the Haxe type system can detect errors at compile-time which would only be noticeable at run-time in the target language. Furthermore, type information can be used by the target generators to generate optimized and robust code.
Currently, there are nine supported target languages which allow for different use-cases:
\begin{tabular}{| l | l | l |}
Name & Output type & Main usages \\ \hline
JavaScript & Sourcecode & Browser, Desktop, Mobile, Server \\
Neko & Bytecode & Desktop, Server, CLI \\
HashLink & Bytecode & Desktop, Mobile, Game consoles \\
PHP & Sourcecode & Server \\
Python & Sourcecode & Desktop, Server \\
Lua & Sourcecode & Desktop, Scripting \\
C++ & Sourcecode & Desktop, Mobile, Server, Game consoles \\
ActionScript 3 & Sourcecode & Desktop, Mobile \\
Flash & Bytecode & Desktop, Mobile \\
Java & Sourcecode & Desktop, Mobile, Server \\
C\# & Sourcecode & Desktop, Mobile, Server \\ \hline
The remainder of section \ref{introduction} gives a brief overview of what a Haxe program looks like and how Haxe evolved since its inception in 2005.
\Fullref{types} introduces the seven different kinds of types in Haxe and how they interact with each other. The discussion of types is continued in \Fullref{type-system}, where features like \emph{unification}, \emph{type parameters} and \emph{type inference} are explained.
\Fullref{class-field} is all about the structure of Haxe classes and, among other topics, deals with \emph{properties}, \emph{inline fields} and \emph{generic functions}.
In \Fullref{expression} we see how to actually get programs to do something by using \emph{expressions}.
\Fullref{lf} describes some of the Haxe features in detail such as \emph{pattern matching}, \emph{string interpolation} and \emph{dead code elimination}. This concludes the Haxe language reference.
We continue with the Haxe compiler reference, which first handles the basics in \Fullref{compiler-usage} before getting into the advanced features in \Fullref{cr-features}. Finally, we will venture into the exciting land of \emph{haxe macros} in \Fullref{macro} to see how some common tasks can be greatly simplified.
In the following chapter, \Fullref{std}, we explore important types and concepts from the Haxe Standard Library. We then learn about Haxe's package manager Haxelib in \Fullref{haxelib}.
Haxe abstracts away many target differences, but sometimes it is important to interact with a target directly, which is the subject of \Fullref{target-details}.
\section{About this Document}
This document is the official manual for Haxe 3. As such, it is not a beginner's tutorial and does not teach programming. However, the topics are roughly designed to be read in order and there are references to topics ``previously seen'' and topics ``yet to come''. In some cases, an earlier section makes use of the information of a later section if it simplifies the explanation. These references are linked accordingly and it should generally not be a problem to read ahead on other topics.
We use a lot of Haxe source code to keep a practical connection of theoretical matters. These code examples are often complete programs that come with a main function and can be compiled as-is. However, sometimes only the most important parts are shown.
Source code looks like this:
Haxe code here
Occasionally, we demonstrate how Haxe code is generated, for which we usually show the \target{JavaScript} target.
Furthermore, we define a set of terms in this document. Predominantly, this is done when introducing a new type or when a term is specific to Haxe. We do not define every new aspect we introduce, e.g. what a class is, to avoid cluttering the text. A definition looks like this:
\define{Definition name}{define-definition}{Definition description}
In a few places, this document has \emph{trivia}-boxes. These include off-the-record information such as why certain decisions were made during Haxe's development or how a particular feature has been changed in past Haxe versions. This information is generally not important and can be skipped as it is only meant to convey trivia:
\trivia{About Trivia}{This is trivia.}
\subsection{Authors and contributions}
Most of this document's content was written by Simon Krajewski while working for the Haxe Foundation. We would like to thank these people for their contributions:
\item Dan Korostelev: Additional content and editing
\item Caleb Harper: Additional content and editing
\item Josefiene Pertosa: Editing
\item Miha Lunar: Editing
\item Nicolas Cannasse: Haxe creator
The Haxe Manual by \href{}{Haxe Foundation} is licensed under a \href{}{Creative Commons Attribution 4.0 International License}.
Based on a work at \href{}{}.
\section{Hello World}
The following program prints ``Hello World'' after being compiled and run:
This can be tested by saving the above code to a file named \ic{Main.hx} and invoking the Haxe Compiler like so: \ic{haxe -main Main --interp}. It then generates the following output: \ic{Main.hx:3: Hello world}. There are several things to learn from this:
\todo{This generates the following output: too many 'this'. You may like a passive sentence: the following output will be generated...though this is to be avoided, generally}
\item Haxe programs are saved in files with an extension of \ic{.hx}.
\item The Haxe Compiler is a command-line tool which can be invoked with parameters such as \ic{-main Main} and \ic{--interp}.
\item Haxe programs have classes (\type{Main}, upper-case), which have functions (\expr{main}, lower-case).
\item The name of the file containing main Haxe class is the same as name of the class itself (in this case \type{Main.hx}).
\paragraph{Related content}
\item \href{}{Beginner tutorials and examples} in the Haxe Code Cookbook.
The Haxe project was started on 22 October 2005 by French developer \emph{Nicolas Cannasse} as a successor to the popular open-source ActionScript 2 compiler \emph{MTASC} (Motion-Twin Action Script Compiler) and the in-house \emph{MTypes} language, which experimented with the application of type inference to an object oriented language. Nicolas' long-time passion for programming language design and the rise of new opportunities to mix different technologies as part of his game developer work at \emph{Motion-Twin} led to the creation of a whole new language.
Being spelled \emph{haXe} back then, its beta version was released in February 2006 with the first supported targets being AVM\footnote{Adobe Virtual Machine}-bytecode and Nicolas' own \emph{Neko} virtual machine\footnote{}.
Nicolas Cannasse, who remains leader of the Haxe project to this date, kept on designing Haxe with a clear vision, subsequently leading to the Haxe 1.0 release in May 2006. This first major release came with support for \target{JavaScript} code generation and already had some of the features that define Haxe today such as type inference and structural sub-typing.
Haxe 1 saw several minor releases over the course of two years, adding the \target{Flash AVM2} target along with the \emph{haxelib}-tool in August 2006 and the \target{ActionScript 3} target in March 2007. During these months, there was a strong focus on improving stability, which resulted in several minor bug-fix releases.
Haxe 2.0 was released in July 2008, including the \target{PHP} target, courtesy of \emph{Franco Ponticelli}. A similar effort by \emph{Hugh Sanderson} lead to the addition of the \target{C++} target in July 2009 with the Haxe 2.04 release.
Just as with Haxe 1, what followed were several months of stability releases. In January 2011, Haxe 2.07 was released with the support of \emph{macros}. Around that time, \emph{Bruno Garcia} joined the team as maintainer of the \target{JavaScript} target, which saw vast improvements in the subsequent 2.08 and 2.09 releases.
After the release of 2.09, \emph{Simon Krajewski} joined the team and work towards Haxe 3 began. Furthermore, \emph{Cau\^{e} Waneck}'s \target{Java} and \target{C\#} targets found their way into the Haxe builds. It was then decided to make one final Haxe 2 release, which happened in July 2012 with the release of Haxe 2.10.
In late 2012, the Haxe 3 switch was flipped and the Haxe Compiler team, now backed by the newly established \emph{Haxe Foundation}\footnote{}, focused on this next major version. Haxe 3 was subsequently released in May 2013.