HaxeFoundation / HaxeFoundation/haxe

Sys.systemName() should use an enum abstract

Open
#6,935 1 comment 1 reaction 0 assignees View on GitHub
standard library
Dominant language
Haxe
Stars
6.9k
Forks
715
Avg merge
2d 2h
Merged PRs (30d)
11

Description

`Sys.systemName()` returns a raw string for something that only has a set of specific / known values. This is quite error-prone, as can be seen here: https://github.com/HaxeFoundation/haxe/pull/6921. It also means no code completion can be offered.

It would be nice to have a `SystemName` enum abstract instead that looks something like this:

```haxe
@:forward @:enum abstract SystemName(String) from String to String {
var Windows = "Windows";
var Linux = "Linux";
var Mac = "Mac";
// etc..
}
```

This should preserve full backwards-compatbility due to `@:forward` and `from String to String`, while still also allowing the use of values not listed in the abstract.

The only open question is which values should actually be included in the enum... all that are known to be returned by at least one target? Just the most commonly supported ones?

________________________

- HXCPP for instance has a few more obscure ones such as `"EPPC"`.

https://github.com/HaxeFoundation/hxcpp/blob/56859a51a881660a1c38411a5128d11b5b299e31/project/libs/std/Sys.cpp#L236-L259

I'm also confused that there seems to be an `"Android"`, but no `"iOS"` in hxcpp?

- HashLink does have `"iOS"` as well as `"tvOS"`:

https://github.com/HaxeFoundation/hashlink/blob/7268d1db6965941bcbb795b5cf4eb8a230db912d/src/std/sys.c#L116-L119

- Lua has `"Solaris"`, which I haven't seen anywhere else:

https://github.com/HaxeFoundation/haxe/blob/66d912161bda072b38d0fdfdaac67236e958e0c2/std/lua/Boot.hx#L370

- @ncannasse [mentioned](https://github.com/HaxeFoundation/haxe/pull/6921#issuecomment-377285744) there's additional values for non-public console backends.

>For the record, we have more exotic system names in some other not open source APIs (XBox, Switch, PS4 etc.)

Not sure if those would belong in a `SystemName` enum or not? Also, it seems a bit problematic consistency-wise if `"XBox"` is used, since the C# Target currently uses `"Xbox"` (lowercase `b`):

https://github.com/HaxeFoundation/haxe/blob/66d912161bda072b38d0fdfdaac67236e958e0c2/std/cs/_std/Sys.hx#L106

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.