Skip to content

Commit 38ba0e4

Browse files
committed
Fix a few parity issues
1 parent 042722e commit 38ba0e4

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

polymod/hscript/_internal/HLWrapperMacro.hx

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
package polymod.hscript._internal;
22

3+
#if (!macro && hl)
4+
@:build(polymod.hscript._internal.HLWrapperMacro.buildWrapperClass())
5+
class HLMath extends Math {}
6+
7+
@:build(polymod.hscript._internal.HLWrapperMacro.buildWrapperClass())
8+
@:haxe.warning("-WDeprecated")
9+
class HLStd extends Std {
10+
public static function is(v:Dynamic, t:Dynamic)
11+
return isOfType(v, t);
12+
13+
public static function isOfType(v:Dynamic, t:Dynamic):Bool
14+
{
15+
// HL oddly uses hl.Bytes for strings sometimes
16+
// We do a hack since we can't just do isOfType(v, hl.Bytes)
17+
if (t == String && !Std.isOfType(v, String))
18+
{
19+
function bytesTest(_:hl.Bytes) {}
20+
try
21+
{
22+
bytesTest(v);
23+
return true;
24+
}
25+
catch (_)
26+
{
27+
return false;
28+
}
29+
}
30+
31+
return Std.isOfType(v, t);
32+
}
33+
}
34+
#else
335
import haxe.macro.MacroStringTools;
436
import haxe.macro.TypedExprTools;
537
import haxe.macro.Context;
@@ -12,14 +44,6 @@ using haxe.macro.ComplexTypeTools;
1244
using haxe.macro.ExprTools;
1345
using StringTools;
1446

15-
#if (!macro && hl)
16-
@:build(polymod.hscript._internal.HLWrapperMacro.buildWrapperClass())
17-
class HLMath extends Math {}
18-
19-
@:build(polymod.hscript._internal.HLWrapperMacro.buildWrapperClass())
20-
@:haxe.warning("-WDeprecated")
21-
class HLStd extends Std {}
22-
#else
2347
/**
2448
* Macro that generates wrapper fields for substitutes of `std` classes to make them avaliable to Reflection.
2549
* Currently only works for static fields.
@@ -144,4 +168,4 @@ class HLWrapperMacro
144168
}
145169
}
146170
}
147-
#end
171+
#end

polymod/hscript/_internal/PolymodInterpEx.hx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,12 @@ class PolymodInterpEx extends Interp
974974
{
975975
try
976976
{
977+
#if hl
978+
// HL is a bit weird with iterators with arguments
979+
v = Reflect.callMethod(v, v.iterator, []);
980+
#else
977981
v = v.iterator();
982+
#end
978983
}
979984
catch (e:Dynamic)
980985
{
@@ -1161,10 +1166,11 @@ class PolymodInterpEx extends Interp
11611166
// #end
11621167
// return result;
11631168
}
1164-
#if hl
1169+
#if (hl && haxe4)
11651170
else if (Std.isOfType(o, Enum))
11661171
{
1167-
try {
1172+
try
1173+
{
11681174
return (o:Enum<Dynamic>).createByName(f);
11691175
}
11701176
catch (e)
@@ -1180,6 +1186,12 @@ class PolymodInterpEx extends Interp
11801186
}
11811187

11821188
// Default behavior
1189+
#if hl
1190+
// On HL, hasField on properties returns true but Reflect.field
1191+
//might return null so we have to check if a getter exists too.
1192+
// This happens mostly when the programmer mistakenly makes the field access (get, null) instead of (get, never)
1193+
return Reflect.getProperty(o, f);
1194+
#else
11831195
if (Reflect.hasField(o, f)) {
11841196
return Reflect.field(o, f);
11851197
} else {
@@ -1189,6 +1201,7 @@ class PolymodInterpEx extends Interp
11891201
return Reflect.field(o, f);
11901202
}
11911203
}
1204+
#end
11921205
// return super.get(o, f);
11931206
}
11941207

0 commit comments

Comments
 (0)