mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-27 07:33:57 +00:00
[haxe] some additions and fixes (closes #489)
This commit is contained in:
parent
f115995171
commit
0e118934db
@ -3,6 +3,7 @@ language: haxe
|
|||||||
filename: LearnHaxe3.hx
|
filename: LearnHaxe3.hx
|
||||||
contributors:
|
contributors:
|
||||||
- ["Justin Donaldson", "https://github.com/jdonaldson/"]
|
- ["Justin Donaldson", "https://github.com/jdonaldson/"]
|
||||||
|
- ["Dan Korostelev", "https://github.com/nadako/"]
|
||||||
---
|
---
|
||||||
|
|
||||||
Haxe is a web-oriented language that provides platform support for C++, C#,
|
Haxe is a web-oriented language that provides platform support for C++, C#,
|
||||||
@ -34,16 +35,20 @@ references.
|
|||||||
/*
|
/*
|
||||||
This is your first actual haxe code coming up, it's declaring an empty
|
This is your first actual haxe code coming up, it's declaring an empty
|
||||||
package. A package isn't necessary, but it's useful if you want to create a
|
package. A package isn't necessary, but it's useful if you want to create a
|
||||||
namespace for your code (e.g. org.module.ClassName).
|
namespace for your code (e.g. org.yourapp.ClassName).
|
||||||
|
|
||||||
|
Omitting package declaration is the same as declaring empty package.
|
||||||
*/
|
*/
|
||||||
package; // empty package, no namespace.
|
package; // empty package, no namespace.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Packages define modules for your code. Each module (e.g. org.module) must
|
Packages are directories that contain modules. Each module is a .hx file
|
||||||
be lower case, and should exist as a folder structure containing the class.
|
that contains types defined in a package. Package names (e.g. org.yourapp)
|
||||||
Class (and type) names must be capitalized. E.g, the class "org.module.Foo"
|
must be lower case while module names are capitalized. A module contain one
|
||||||
should have the folder structure org/module/Foo.hx, as accessible from the
|
or more types whose names are also capitalized.
|
||||||
compiler's working directory or class path.
|
|
||||||
|
E.g, the class "org.yourapp.Foo" should have the folder structure org/module/Foo.hx,
|
||||||
|
as accessible from the compiler's working directory or class path.
|
||||||
|
|
||||||
If you import code from other files, it must be declared before the rest of
|
If you import code from other files, it must be declared before the rest of
|
||||||
the code. Haxe provides a lot of common default classes to get you started:
|
the code. Haxe provides a lot of common default classes to get you started:
|
||||||
@ -53,6 +58,12 @@ import haxe.ds.ArraySort;
|
|||||||
// you can import many classes/modules at once with "*"
|
// you can import many classes/modules at once with "*"
|
||||||
import haxe.ds.*;
|
import haxe.ds.*;
|
||||||
|
|
||||||
|
// you can import static fields
|
||||||
|
import Lambda.array;
|
||||||
|
|
||||||
|
// you can also use "*" to import all static fields
|
||||||
|
import Math.*;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
You can also import classes in a special way, enabling them to extend the
|
You can also import classes in a special way, enabling them to extend the
|
||||||
functionality of other classes like a "mixin". More on 'using' later.
|
functionality of other classes like a "mixin". More on 'using' later.
|
||||||
@ -172,7 +183,8 @@ class LearnHaxe3{
|
|||||||
Regexes are also supported, but there's not enough space to go into
|
Regexes are also supported, but there's not enough space to go into
|
||||||
much detail.
|
much detail.
|
||||||
*/
|
*/
|
||||||
trace((~/foobar/.match('foo')) + " is the value for (~/foobar/.match('foo')))");
|
var re = ~/foobar/;
|
||||||
|
trace(re.match('foo') + " is the value for (~/foobar/.match('foo')))");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Arrays are zero-indexed, dynamic, and mutable. Missing values are
|
Arrays are zero-indexed, dynamic, and mutable. Missing values are
|
||||||
@ -383,11 +395,7 @@ class LearnHaxe3{
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// if statements
|
// if statements
|
||||||
var k = if (true){
|
var k = if (true) 10 else 20;
|
||||||
10;
|
|
||||||
} else {
|
|
||||||
20;
|
|
||||||
}
|
|
||||||
|
|
||||||
trace("K equals ", k); // outputs 10
|
trace("K equals ", k); // outputs 10
|
||||||
|
|
||||||
@ -628,6 +636,7 @@ enum ComplexEnum{
|
|||||||
ComplexEnumEnum(c:ComplexEnum);
|
ComplexEnumEnum(c:ComplexEnum);
|
||||||
}
|
}
|
||||||
// Note: The enum above can include *other* enums as well, including itself!
|
// Note: The enum above can include *other* enums as well, including itself!
|
||||||
|
// Note: This is what called *Algebraic data type* in some other languages.
|
||||||
|
|
||||||
class ComplexEnumTest{
|
class ComplexEnumTest{
|
||||||
public static function example(){
|
public static function example(){
|
||||||
|
Loading…
Reference in New Issue
Block a user