Improve lime.tools.Platform type safety.

We shouldn't have to cast it every time!
This commit is contained in:
Joseph Cloutier
2024-01-12 15:12:24 -05:00
parent 31ad76f888
commit 9718b8a454
3 changed files with 25 additions and 19 deletions

View File

@@ -87,7 +87,7 @@ class HXProject extends Script
var outputFile = args[1];
HXProject._command = inputData.command;
HXProject._target = cast inputData.target;
HXProject._target = inputData.target;
HXProject._debug = inputData.debug;
HXProject._targetFlags = inputData.targetFlags;
HXProject._templatePaths = inputData.templatePaths;
@@ -742,7 +742,7 @@ class HXProject extends Script
defines.set("uwp", "1");
defines.set("winjs", "1");
}
else if (platformType == DESKTOP && target != cast System.hostPlatform)
else if (platformType == DESKTOP && target != System.hostPlatform)
{
defines.set("native", "1");
@@ -834,7 +834,7 @@ class HXProject extends Script
{
if (_target == null)
{
_target = cast System.hostPlatform;
_target = System.hostPlatform;
}
if (_targetFlags == null)
@@ -1040,7 +1040,7 @@ class HXProject extends Script
// Getters & Setters
private function get_host():Platform
{
return cast System.hostPlatform;
return System.hostPlatform;
}
private function get_templateContext():Dynamic

View File

@@ -1,6 +1,6 @@
package lime.tools;
#if (haxe_ver >= 4.0) enum #else @:enum #end abstract Platform(String)
#if (haxe_ver >= 4.0) enum #else @:enum #end abstract Platform(String) from hxp.HostPlatform
{
var AIR = "air";
var ANDROID = "android";
@@ -24,4 +24,10 @@ package lime.tools;
var EMSCRIPTEN = "emscripten";
var TVOS = "tvos";
var CUSTOM = null;
@:op(A == B) @:commutative
private inline function equalsHostPlatform(hostPlatform:hxp.HostPlatform):Bool
{
return this == hostPlatform;
}
}

View File

@@ -231,31 +231,31 @@ class CommandLineTools
switch (targetName)
{
case "cpp":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cpp", "");
case "neko":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("neko", "");
case "hl", "hashlink":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("hl", "");
case "cppia":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cppia", "");
case "java":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("java", "");
case "nodejs":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("nodejs", "");
case "cs":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cs", "");
case "iphone", "iphoneos":
@@ -1511,31 +1511,31 @@ class CommandLineTools
switch (targetName)
{
case "cpp":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cpp", "");
case "neko":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("neko", "");
case "hl", "hashlink":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("hl", "");
case "cppia":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cppia", "");
case "java":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("java", "");
case "nodejs":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("nodejs", "");
case "cs":
target = cast System.hostPlatform;
target = System.hostPlatform;
targetFlags.set("cs", "");
case "iphone", "iphoneos":