HaxeFoundation / HaxeFoundation/haxe

[SUGGESTION]: Package-level fields

Open
#12,692 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

Module-level fields have been introduced since Haxe 4.2.0 to open the possibilities of procedural programming in Haxe (according to https://haxe.org/blog/module-level-fields/)

since this is an option, I believe it'd made sense to open the possibilities of package-level functions like ActionScript had in some instances like `flash.media.scanHardware` or `flash.system.fscommand`.

My suggestion would be to allow (maybe for the first time ever) a lower-case .hx file called `package.hx` or the name of the package itself (i.e. `audio.hx` in `system.audio`), which would be another way to implement classes in a single file module but be spread within the package.

Example:

```hx
package dot.addons;
//in package.hx
class Foo
{
public static function myFunc()
{
trace("calling from Foo");
}
}
class Bar
{
public static function myFunc()
{
trace("calling from Bar");
}
}
```

```hx
// Main.hx

import dot.addons.Foo;
import dot.addons.Bar;

function main()
{
Foo.myFunc();
Bar.myFunc();
}
```

and, with the insertion of module-level fields, you could now do this:
```hx
// in package.hx
package dot.addons;

function analyzeParams()
{
// code block...
}
```

```hx
// Main.hx

import dot.addons.analyzeParams;

function main()
{
analyzeParams();
}
```

this would be proper for stb single files that are not necessary for them to be within a class in Haxe.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.