Created
June 14, 2016 00:06
-
-
Save francescoagati/a1f4852ecc6b791128335541f722a279 to your computer and use it in GitHub Desktop.
haxe abstract and inline objects
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
class Getter<T> { | |
var name:String; | |
var obj:T; | |
public inline function new(name:String,obj:T) { | |
this.name = name; | |
this.obj = obj; | |
} | |
public inline function get() return untyped (obj:haxe.DynamicAccess<Dynamic>)[name]; | |
} | |
abstract Resolver(Dynamic) from Dynamic to Dynamic { | |
@:resolve public inline function resolver(name:String) { | |
return new Getter(name,this); | |
} | |
} | |
class Main { | |
static function main() { | |
var wrapper:Resolver = untyped {a:1}; | |
trace(wrapper.a.get()); | |
} | |
} |
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.main = function() { | |
var wrapper = { a : 1}; | |
var _this_name = "a"; | |
var _this_obj = wrapper; | |
console.log(_this_obj[_this_name]); | |
}; | |
Main.main(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment