-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStd.hx
More file actions
executable file
·68 lines (56 loc) · 1.99 KB
/
Std.hx
File metadata and controls
executable file
·68 lines (56 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package;
extern class Std {
@:deprecated('Std.is is deprecated. Use Std.isOfType instead.') @:runtime public inline static function is(v:Dynamic, t:Dynamic):Bool
return isOfType(v, t);
@:nativeFunctionCode("Type({arg0}) = {arg1}")
public static function isOfType(v:Dynamic, t:Dynamic):Bool;
@:deprecated('Std.instance() is deprecated. Use Std.downcast() instead.')
@:runtime public inline static function instance<T:{}, S:T>(value:T, c:Class<S>):S
return downcast(value, c);
@:nativeFunctionCode("{arg0}")
public static function downcast<T:{}, S:T>(value:T, c:Class<S>):S;
@:nativeFunctionCode('__DynToStr__({arg0})')
public static function string(s:Dynamic):String;
@:nativeFunctionCode("Int({arg0})")
public static function int(x:Float):Int;
@:nativeFunctionCode("StrToI({arg0})")
public static function parseInt(x:String):Null<Int>;
@:nativeFunctionCode("StrToI({arg0})")
public static function parseFloat(x:String):Float;
@:nativeFunctionCode("Rnd({arg0})")
public static function random(x:Int):Int;
}
@:keep @:brs_global function __DynToStr__(a:Dynamic) {
final dynType = brs.Native.typeOf(a);
return switch dynType {
case 'roString' | 'String': a;
case 'roInt' | 'Integer': untyped __brs__('Str({0})', a);
case 'roBoolean' | 'Boolean': untyped __brs__('{0}.ToStr()', a);
case 'roFloat' | 'Float': untyped __brs__('Str({0})', a);
case 'roDouble': untyped __brs__('Str({0})', a);
case 'roArray':
untyped __brs__('
s = ""
for i = 0 to {0}.Count()-1
If i > 0 Then
del = {1}
Else
del = ""
end If
s = s + del + __DynToStr__({0}[i])
end for', a, ', ');
'[${untyped __brs__("s")}]';
case 'roAssociativeArray':
untyped __brs__('
s = "{"
keys = {0}.Keys()
for i = 0 to keys.Count() - 1
if i > 0 then s = s + ", "
s = s + keys[i] + ": " + __DynToStr__({0}[keys[i]])
end for
s = s + "}"', a);
'[${untyped __brs__("s")}]';
case 'Function': '[Function]';
case _: throw 'ERROR: NOT_IMPLEMENTED__DynToStr__($dynType)';
}
}