Skip to content

Commit

Permalink
Improve lime.tools.Platform type safety.
Browse files Browse the repository at this point in the history
We shouldn't have to cast it every time!
  • Loading branch information
player-03 committed Jan 12, 2024
1 parent 31ad76f commit 9718b8a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/lime/tools/HXProject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -834,7 +834,7 @@ class HXProject extends Script
{
if (_target == null)
{
_target = cast System.hostPlatform;
_target = System.hostPlatform;
}

if (_targetFlags == null)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/lime/tools/Platform.hx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}
}
28 changes: 14 additions & 14 deletions tools/CommandLineTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 9718b8a

Please sign in to comment.