Last active
June 26, 2016 23:50
-
-
Save skial/3a38fa5fc19d2a3ae6d06d9ec0899fbd to your computer and use it in GitHub Desktop.
Haxe 3.3.0-rc.1 Abstract @:resolve and @:op(a.b) metadata simplified examples.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import haxe.macro.Expr; | |
class Main { | |
static function main() { | |
var smap:StringMap = ['firstName' => 'Skial', 'lastName' => 'Bainn']; | |
trace( smap.lastName, smap.firstName ); // Bainn, Skial | |
var mmap:MacroMap = cast smap; | |
trace( mmap.lastName, mmap.firstName ); // Bainn, Skial | |
} | |
} | |
abstract StringMap(Map<String, String>) from Map<String, String> { | |
@:resolve | |
private inline function resolve(name:String) { | |
return this.get( name ); | |
} | |
} | |
abstract MacroMap(Map<String, String>) from Map<String, String> { | |
@:op(a.b) | |
private static macro function resolve(ethis:Expr, name:String) { | |
var result = switch (name) { | |
case 'firstName': 'Skial'; | |
case 'lastName': 'Bainn'; | |
case _: ''; | |
} | |
return macro $v { result }; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by Haxe 3.3.0 | |
(function () { "use strict"; | |
var Main = function() { }; | |
Main.__name__ = true; | |
Main.main = function() { | |
var _g = new haxe_ds_StringMap(); | |
if(__map_reserved.firstName != null) { | |
_g.setReserved("firstName","Skial"); | |
} else { | |
_g.h["firstName"] = "Skial"; | |
} | |
if(__map_reserved.lastName != null) { | |
_g.setReserved("lastName","Bainn"); | |
} else { | |
_g.h["lastName"] = "Bainn"; | |
} | |
var smap = _g; | |
var _this = smap; | |
var tmp = __map_reserved.lastName != null?_this.getReserved("lastName"):_this.h["lastName"]; | |
var _this1 = smap; | |
haxe_Log.trace(tmp,{ fileName : "Main.hx", lineNumber : 10, className : "Main", methodName : "main", customParams : [__map_reserved.firstName != null?_this1.getReserved("firstName"):_this1.h["firstName"]]}); | |
haxe_Log.trace("Bainn",{ fileName : "Main.hx", lineNumber : 13, className : "Main", methodName : "main", customParams : ["Skial"]}); | |
}; | |
Main.main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment