Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
e01f679
parseInt and toString args, DMDynamic for some flash classes, cancelC…
AxGord May 7, 2021
394346e
Embed and other metadata
AxGord May 12, 2021
17ecc1f
Xml list methods, unescape
AxGord May 17, 2021
6f35105
ByteArray array access return uint. Xml child.
AxGord May 18, 2021
11b6dbe
replaceControlChars, disable run after build, rebuild
AxGord May 19, 2021
35c07ff
mkString, file meta string
AxGord May 20, 2021
fc72989
semiliconBefore else if need
AxGord May 20, 2021
86507ca
ArrayElementType meta, rewrite new array fix error
AxGord May 26, 2021
a1f9325
Convert type for ArrayElementType meta
AxGord May 28, 2021
6e64af3
ASCompat parseInt, escape and unescape
AxGord May 28, 2021
d9d6863
using Сast instead of downcast
AxGord Jun 1, 2021
b80dda4
import Error
AxGord Jun 4, 2021
86190e0
as ByteArray
AxGord Jun 4, 2021
160347b
Rest arg for new haxe
AxGord Jun 7, 2021
418a2b0
Keeping public getters and setters if need
AxGord Jun 14, 2021
1c76202
Xml name. Meta: HxOverride, HxCancelOverride, HxRemove
AxGord Jun 15, 2021
f68964c
RegExpResult
AxGord Jun 18, 2021
5cb1a98
ArrayElementType Array
AxGord Jun 18, 2021
3da4bb3
Rest as Array
AxGord Jun 18, 2021
2fc38fd
XMLList appendChild and children. HxForceProp meta.
AxGord Jun 23, 2021
9818a6b
getUTCDate
AxGord Jun 23, 2021
94887e7
RewriteArrayTypes. TFFun ArrayElementType. XML attributes.
AxGord Jun 28, 2021
2716d83
Function length for js. XML to String. keepTypes option. isVar meta f…
AxGord Jun 29, 2021
be35984
Change isVector check method
AxGord Jul 5, 2021
6c5529f
isOfType, js.Syntax, ByteArray to ByteArrayData for is
AxGord Jul 6, 2021
c002d1b
Rebuild
AxGord Jul 6, 2021
57a49a0
Copy data options
AxGord Jul 8, 2021
1aa5bd8
Skip namespace, unpack swc
AxGord Jul 14, 2021
04f82bf
datafiles, hxoutClean, dataoutClean, formatter, copy, _isVector fix
AxGord Jul 16, 2021
45f4ac5
Attribute abstract
AxGord Jul 28, 2021
cdcc795
bitmap meta
AxGord Aug 24, 2021
faf8b24
Control chars, rebuild
AxGord Oct 12, 2021
51bd2ab
HxArrayArgType as3 meta
AxGord Nov 3, 2021
99f5cf0
Rewrite Dictionary and Object Types
AxGord Nov 30, 2021
896e230
Null check for RegExpResult
AxGord Jan 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# -cmd cp java_out/Main-debug.jar converter.jar
-cmd cp java_out/Main.jar converter.jar

-cmd java -jar converter.jar config-local.json
# -cmd java -jar converter.jar config-local.json
10 changes: 5 additions & 5 deletions compat/ASAny.hx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract ASAny(Dynamic)
if (this == null) {
return false;
}
if (Std.is(this, Float)) {
if (Std.isOfType(this, Float)) {
var v:Float = cast this;
return v != 0 && !Math.isNaN(v);
}
Expand All @@ -64,18 +64,18 @@ abstract ASAny(Dynamic)
if (this == null) {
return 0;
}
if (Std.is(this, Int)) {
if (Std.isOfType(this, Int)) {
return cast this;
}
if (Std.is(this, Float)) {
if (Std.isOfType(this, Float)) {
var v:Float = cast this;
return if (Math.isNaN(v)) 0 else Std.int(v);
}
if (Std.is(this, String)) {
if (Std.isOfType(this, String)) {
var i = Std.parseInt(cast this);
return if (i == null) 0 else i;
}
if (Std.is(this, Bool)) {
if (Std.isOfType(this, Bool)) {
return if (cast this) 1 else 0;
}
return 0;
Expand Down
60 changes: 56 additions & 4 deletions compat/ASCompat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class ASCompat {
#end
}

public static inline function unescape(s:String):String {
#if flash
return untyped __global__["unescape"](s);
#else
return js.Lib.global.unescape(s);
#end
}

#if flash
public static inline function describeType(value:Any):compat.XML {
return flash.Lib.describeType(value);
Expand Down Expand Up @@ -167,10 +175,9 @@ class ASCompat {
public static macro function asVector<T>(value:Expr, typecheck:Expr):ExprOf<Null<flash.Vector<T>>>;
public static macro function isVector<T>(value:Expr, typecheck:Expr):ExprOf<Bool>;

#if !flash
@:noCompletion public static inline function _asVector<T>(value:Any):Null<flash.Vector<T>> return if (openfl.Vector.isVector(value)) value else null;
@:noCompletion public static inline function _isVector(value:Any):Bool return openfl.Vector.isVector(value);
#end
@:noCompletion public static inline function _asVector<T>(value:Any):Null<flash.Vector<T>> return if (_isVector(value)) value else null;
@:noCompletion public static inline function _isVector(value:Any):Bool
return Reflect.hasField(value, '__array') && Reflect.hasField(value, 'fixed');

public static inline function asFunction(v:Any):Null<ASFunction> {
return if (Reflect.isFunction(v)) v else null;
Expand Down Expand Up @@ -221,6 +228,51 @@ class ASCompat {
return !!v;
#end
}

/**
* https://github.com/HaxeFoundation/as3hx/blob/829f661777d0458c7902c4235a4c944de4c8cc6d/src/as3hx/Compat.hx#L114
*/
public static function parseInt(s:String, ?base:Int):Null<Int> {
#if js
if (base == null) base = s.indexOf("0x") == 0 ? 16 : 10;
var v:Int = js.Syntax.code("parseInt({0}, {1})", s, base);
return Math.isNaN(v) ? null : v;
#elseif flash
if (base == null) base = 0;
var v:Int = untyped __global__["parseInt"](s, base);
return Math.isNaN(v) ? null : v;
#else
var BASE = "0123456789abcdefghijklmnopqrstuvwxyz";
if (base != null && (base < 2 || base > BASE.length))
return throw 'invalid base ${base}, it must be between 2 and ${BASE.length}';
s = s.trim().toLowerCase();
var sign = if (s.startsWith("+")) {
s = s.substring(1);
1;
} else if (s.startsWith("-")) {
s = s.substring(1);
-1;
} else {
1;
};
if (s.length == 0) return null;
if (s.startsWith('0x')) {
if (base != null && base != 16) return null; // attempting at converting a hex using a different base
base = 16;
s = s.substring(2);
} else if (base == null) {
base = 10;
}
var acc = 0;
try s.split('').map(function(c) {
var i = BASE.indexOf(c);
if(i < 0 || i >= base) throw 'invalid';
acc = (acc * base) + i;
}) catch(e:Dynamic) {};
return acc * sign;
#end
}

}

class ASArray {
Expand Down
2 changes: 1 addition & 1 deletion compat/ASDictionary.hx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract ASDictionary<K,V>(Dictionary<K,V>) from Dictionary<K,V> to Dictionary<K
#if flash
return flash.Lib.as(v, flash.utils.Dictionary);
#else
return if (Std.is(v, haxe.Constraints.IMap)) v else null;
return if (Std.isOfType(v, haxe.Constraints.IMap)) v else null;
#end
}

Expand Down
13 changes: 12 additions & 1 deletion compat/ASFunction.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ abstract ASFunction(Dynamic)
to (Dynamic,Dynamic,Dynamic,Dynamic)->Dynamic
to (Dynamic,Dynamic,Dynamic,Dynamic,Dynamic)->Dynamic
to (Dynamic,Dynamic,Dynamic,Dynamic,Dynamic,Dynamic)->Dynamic
{}
{

#if js
public var length(get, never): Int;

private function get_length(): Int {
final f = this;
return js.Syntax.code('f.length');
}
#end

}
#end
10 changes: 5 additions & 5 deletions compat/ASObject.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract ASObject(flash.utils.Object)
if (this == null) {
return false;
}
if (Std.is(this, Float)) {
if (Std.isOfType(this, Float)) {
var v:Float = cast this;
return v != 0 && !Math.isNaN(v);
}
Expand All @@ -74,18 +74,18 @@ abstract ASObject(flash.utils.Object)
if (this == null) {
return 0;
}
if (Std.is(this, Int)) {
if (Std.isOfType(this, Int)) {
return cast this;
}
if (Std.is(this, Float)) {
if (Std.isOfType(this, Float)) {
var v:Float = cast this;
return if (Math.isNaN(v)) 0 else Std.int(v);
}
if (Std.is(this, String)) {
if (Std.isOfType(this, String)) {
var i = Std.parseInt(cast this);
return if (i == null) 0 else i;
}
if (Std.is(this, Bool)) {
if (Std.isOfType(this, Bool)) {
return if (cast this) 1 else 0;
}
return 0;
Expand Down
9 changes: 9 additions & 0 deletions compat/compat/Attribute.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package compat;

@:transitive abstract Attribute(String) from String to String {

@:op(a == b) private inline function equal(b: Any): Bool return this == b || (this == '' && b == null);
@:op(a != b) private inline function notEqual(b: Any): Bool return !equal(b);
@:op(a + b) private inline function add(b: String): String return this + b;

}
16 changes: 14 additions & 2 deletions compat/compat/RegExp.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package compat;

#if js
import js.lib.RegExp.RegExpMatch;
#end
import haxe.extern.EitherType;
import haxe.Constraints.Function;

Expand All @@ -11,7 +13,7 @@ abstract RegExp(RegExpImpl) {
this = new RegExpImpl(pattern, options);
}

public inline function exec(s:String) /*infer the type from `return`*/ {
public inline function exec(s:String): RegExpResult {
return this.exec(s);
}

Expand Down Expand Up @@ -41,3 +43,13 @@ abstract RegExp(RegExpImpl) {
return (cast s).split(this);
}
}

#if js
abstract RegExpResult(RegExpMatch) from RegExpMatch to RegExpMatch {

@:to public function toString(): Null<String> return this != null ? this[0] : null;

}
#else
typedef RegExpResult = Dynamic;
#end
32 changes: 30 additions & 2 deletions compat/compat/XML.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
#end
}

public inline function attribute(name:String):String {
public inline function attribute(name:String):Attribute {
#if flash
return this.attribute(name).toString();
#else
Expand All @@ -30,6 +30,14 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
#end
}

public inline function attributes() {
#if flash
return this.attributes();
#else
return [for (a in this.attributes()) {name: () -> a, localName: () -> a, toString: () -> a}];
#end
}

public inline function setAttribute(name:String, value:String):String {
#if flash
this.attribute(name)[0] = new flash.xml.XML(value);
Expand All @@ -47,6 +55,14 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
#end
}

public function elements():XMLList {
#if flash
return this.elements();
#else
return [for (x in this.elements()) x];
#end
}

public function children():XMLList {
#if flash
return this.children();
Expand All @@ -63,6 +79,14 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
#end
}

public function name():String {
#if flash
return this.localName();
#else
return this.nodeName;
#end
}

public function descendants(name:String):XMLList {
#if flash
return this.descendants(name);
Expand All @@ -85,7 +109,8 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
#end

#if flash inline #end
public function toString():String {
@:to public function toString():String {
if (this == null) return null;
#if flash
return this.toString();
#else
Expand All @@ -109,4 +134,7 @@ abstract XML(XMLImpl) from XMLImpl to XMLImpl {
return this.toString();
#end
}

public inline function namespace():Any return null; // todo

}
23 changes: 22 additions & 1 deletion compat/compat/XMLList.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package compat;

import haxe.Exception;
import Xml as StdXml;

private typedef XMLListImpl = #if flash flash.xml.XMLList #else Array<XML> #end;
Expand All @@ -14,14 +15,34 @@ abstract XMLList(XMLListImpl) from XMLListImpl to XMLListImpl {
}

#if flash inline #end
public function attribute(name:String):String {
public function attribute(name:String):Attribute {
#if flash
return this.attribute(name).toString();
#else
return [for (x in this) x.attribute(name)].join("");
#end
}

#if flash inline #end
public function appendChild(v:XML):Void {
#if flash
this.appendChild(v);
#else
for (x in this) x.appendChild(v);
#end
}

#if flash inline #end
public function children():XMLList {
#if flash
return this.children();
#else
final r: Array<XML> = [];
for (x in this) for (e in x.children()) r.push(e);
return r;
#end
}

#if flash inline #end
public function toXMLString():String {
#if flash
Expand Down
Binary file modified converter.jar
Binary file not shown.
Binary file modified run.n
Binary file not shown.
18 changes: 16 additions & 2 deletions src/ax3/Context.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import haxe.extern.EitherType;
import haxe.DynamicAccess;
import ax3.Utils.printerr;

using StringTools;

enum abstract ToplevelImportKind(String) to String {
var Import = "import";
var Using = "using";
Expand All @@ -16,6 +18,8 @@ class Context {

public function new(config:Config) {
this.config = config;
if (config.dataout != null && !config.dataout.endsWith('/')) config.dataout += '/';
if (config.unpackout != null && !config.unpackout.endsWith('/')) config.unpackout += '/';
}

public function reportError(path:String, pos:Int, message:String) {
Expand All @@ -30,14 +34,24 @@ class Context {
}

typedef Config = {
var src:EitherType<String,Array<String>>;
var swc:Array<String>;
var ?src:EitherType<String,Array<String>>;
var ?swc:Array<String>;
var ?skipFiles:Array<String>;
var ?hxout:String;
var ?injection:InjectionConfig;
var ?haxeTypes:DynamicAccess<HaxeTypeAnnotation>;
var ?rootImports:String;
var ?settings:Settings;
var ?keepTypes:Bool;
var ?dataout:String;
var ?dataext:Array<String>;
var ?datafiles:Array<String>;
var ?unpackout:String;
var ?unpackswc:Array<String>;
var ?hxoutClean:Bool;
var ?dataoutClean:Bool;
var ?formatter:Bool;
var ?copy:Array<{unit: String, to: String}>;
}

typedef InjectionConfig = {
Expand Down
Loading