Skip to content

Instantly share code, notes, and snippets.

@boozook
Forked from skial/Main.hx
Created June 26, 2016 23:50
Show Gist options
  • Save boozook/000715f82a7b770dd209d52e54227f31 to your computer and use it in GitHub Desktop.
Save boozook/000715f82a7b770dd209d52e54227f31 to your computer and use it in GitHub Desktop.
Haxe 3.3.0-rc.1 Abstract @:resolve and @:op(a.b) metadata simplified examples.
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 };
}
}
// 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