From 2d672ddf09f43ff39e192cb0d8ef8d8381d73d91 Mon Sep 17 00:00:00 2001 From: Marcelo Silva Nascimento Mancini Date: Fri, 8 Oct 2021 13:40:43 -0300 Subject: [PATCH 1/4] Update 02-types.md Added function overload Added function rest arguments --- content/02-types.md | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/content/02-types.md b/content/02-types.md index 946848bb..b9a7bbbf 100644 --- a/content/02-types.md +++ b/content/02-types.md @@ -745,8 +745,69 @@ Default values in Haxe are not part of the type and are not replaced at the call This should be considered in performance-critical code where a solution without default values may sometimes be more viable. + +#### Overloads +Functions can be overloaded by attaching `extern inline overload` to its siganture. Extern functions don't generate a body, while inline makes extern +able to define the function body, so they're really necessary. +```haxe +class Test { + static function main() { + trace(add(50, 100)); + trace(add(50.50, 100)); + } + + public static extern inline overload function add(a : Float, b : Float) : Float + { + trace("Float!"); + return a + b; + } + public static extern inline overload function add(a : Int, b : Int) : Int + { + trace("Int!"); + return a + b; + } +} + +``` + +This will print +``` +Test.hx:14:,Int! +Test.hx:3:,150 +Test.hx:9:,Float! +Test.hx:4:,150.5 +``` + + +#### Rest Arguments + +Functions can receive a list of arguments without specifying the array syntax by using the following syntax: `...varName`: + +```haxe + +class Test +{ + static function main() + { + logAll("hello", "world", "rest", "arguments"); + } + static function logAll(...arguments : String) + { + for(arg in arguments) + trace(arg); + } +} +``` + +Output: +``` +Test.hx:10:,hello +Test.hx:10:,world +Test.hx:10:,rest +Test.hx:10:,arguments +``` ### Dynamic From 2760d12b44d4743a9f390edb626d6f2f94dd2184 Mon Sep 17 00:00:00 2001 From: Marcelo Silva Nascimento Mancini Date: Fri, 8 Oct 2021 14:08:29 -0300 Subject: [PATCH 2/4] Update 02-types.md Added version in which they were introduced --- content/02-types.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/02-types.md b/content/02-types.md index b9a7bbbf..6e7c217e 100644 --- a/content/02-types.md +++ b/content/02-types.md @@ -780,6 +780,8 @@ Test.hx:9:,Float! Test.hx:4:,150.5 ``` +Function overloading by using the extern keyword were introduced in Haxe 4.2.0; + #### Rest Arguments @@ -809,6 +811,8 @@ Test.hx:10:,rest Test.hx:10:,arguments ``` +Rest arguments were introduced in Haxe 4.2.0. + ### Dynamic From ad54549636e3c42c3c618acd373d0ec2c97b90f0 Mon Sep 17 00:00:00 2001 From: Marcelo Silva Nascimento Mancini Date: Sat, 9 Oct 2021 11:10:43 -0300 Subject: [PATCH 3/4] Update 02-types.md Added documentation reference and a notice to the spread operator --- content/02-types.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/content/02-types.md b/content/02-types.md index 6e7c217e..f96d5cfb 100644 --- a/content/02-types.md +++ b/content/02-types.md @@ -811,8 +811,12 @@ Test.hx:10:,rest Test.hx:10:,arguments ``` +Notice that it is also possible to use spread syntax: `logAll(...["hello", "world"]);` + Rest arguments were introduced in Haxe 4.2.0. +For further information on Rest arguments and Rest operator, check the [documentation](https://api.haxe.org/haxe/Rest.html) + ### Dynamic From 242cd052b4cc6b15443ac996c724c460fa554b43 Mon Sep 17 00:00:00 2001 From: Marcelo Silva Nascimento Mancini Date: Sat, 9 Oct 2021 11:42:00 -0300 Subject: [PATCH 4/4] Update 02-types.md --- content/02-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/02-types.md b/content/02-types.md index f96d5cfb..101a3906 100644 --- a/content/02-types.md +++ b/content/02-types.md @@ -748,7 +748,7 @@ This should be considered in performance-critical code where a solution without #### Overloads -Functions can be overloaded by attaching `extern inline overload` to its siganture. Extern functions don't generate a body, while inline makes extern +Functions can be overloaded by attaching `extern inline overload` to its signature. Extern functions don't generate a body, while inline makes extern able to define the function body, so they're really necessary. ```haxe