elsassph / nme-tilelayer

Lightweight wrapper over NME's powerful but lowlevel 'drawTiles', with bitmap-based fallback for Flash.
92 stars 11 forks source link

Haxe 3 compatibility #13

Closed as3boyan closed 11 years ago

as3boyan commented 11 years ago

Looks like there is no more haxe.Public. So I made some fields public. And Hash -> Map.

elsassph commented 11 years ago

Thanks, there is a new meta tag that replace this feature, but I removed haxe.Public anyway the same way as you did. I'll push that soon. Is Map Haxe3 only or will it still work in Haxe 2?

as3boyan commented 11 years ago

Explanation: Haxe 2 provided map data structures for Int and String keys. With haxe 3 it is possible to use most objects as keys through a single, toplevel Map class. The generated code automatically uses data structures optimized for the chosen key type.

http://haxe.org/manual/haxe3/features

But this Map structure I think it's new. I tested it in Haxe 2.10, compiler can't find class Map. So it should be new. http://haxe.org/manual/haxe3/migration

elsassph commented 11 years ago

If the Hash still works in Haxe 3 (maybe as a Map subclass) I prefer keeping it.

as3boyan commented 11 years ago

No, it won't work. If Hash still worked, then there were no need to change it.

But it won't work in Haxe 3. Map is just same thing, it's just allows to use more objects as keys.

Haxe.org documentation says this: Haxe 3 Migration: Hash and IntHash removal Compiler error "Hash has been removed, use Map instead" or "IntHash has been removed, use Map instead"

Hash and IntHash classes were removed in Haxe 3.

// haxe 2 var hash = new Hash(); var intHash = new IntHash(); "var typedHash : Hash;"

// haxe 3 var hash = new Map(); var intHash = new Map(); "var typedHash : Map<String,MyClass>;"

hash.set("foo", 1); intHash.set(1, 2);

Github completition removed types. so it should look like this, just another brackets should be used. var typedHash : Hash[MyClass] ; var typedHash : Map [String,MyClass];

as3boyan commented 11 years ago
//haxe 2
var typedHash : Hash <MyClass>;

//haxe 3
var typedHash : Map <String, MyClass>;

Just read this: http://haxe.org/manual/haxe3/migration

elsassph commented 11 years ago

Yep I saw that - I just don't want to litter the code with "if haxe3".

as3boyan commented 11 years ago

In NME(maybe you already seen this) it looks like this:

public static var className = new #if haxe3 Map <String, #else Hash <#end Dynamic> ();

RealyUniqueName(creator of StablexDL) did it smart way:

#if haxe3
private typedef Hash<T> = Map<String,T>;
#end

This is very smart way I think, and easy to read and use. But I haven't tested this. And after porting to Haxe 3 I tested your nme-runnermark on neko target, looks like there are some problems(Haxe 3, Neko 2).

elsassph commented 11 years ago

I definitely like the typedef option.

elsassph commented 11 years ago

I'll look at it as part of a new, Haxe3/openFL dedicated, library.