Created
June 5, 2012 11:54
-
-
Save ccapndave/2874561 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ember; | |
| import haxe.macro.Expr; | |
| import haxe.macro.Context; | |
| @:autoBuild(ember.GetterSetterBuilder.build()) | |
| @:native("Ember.Object") | |
| extern class Object { | |
| public function new():Void; | |
| public function init():Void; | |
| public function get(field:String):Dynamic; | |
| public function set(field:String, value:Dynamic):Dynamic; | |
| // TODO: We want a macro that intercepts properties and makes them use get and set | |
| } | |
| class GetterSetterBuilder { | |
| @:macro static public function build():Array<Field> { | |
| var fields = Context.getBuildFields(); | |
| var cls = Context.getLocalClass().get(); | |
| var pos = haxe.macro.Context.currentPos(); | |
| var newFields = []; | |
| for (field in fields) { | |
| var isPublic = false, isStatic = false; | |
| switch (field.kind) { | |
| case FVar(t, e): | |
| for (a in field.access) { | |
| switch (a) { | |
| case APublic: isPublic = true; | |
| case AStatic: isStatic = true; | |
| default: | |
| } | |
| } | |
| if (isPublic && !isStatic) { | |
| trace("HERE!!!" + cls.module + "." + field.name); | |
| var name = "hello" + field.name + "" + Math.abs(Math.floor(Math.random() * 999999999999999)); | |
| var tint = TPath( { pack : [], name : "Int", params : [], sub : null } ); | |
| //var f = ; | |
| newFields.push({ | |
| name: name, | |
| doc: null, | |
| meta: [], | |
| access: [APublic], | |
| kind: FFun( { | |
| args: [], | |
| ret: null, | |
| expr: { expr: EBlock([Context.parse('trace(1)', pos)]), pos: pos }, | |
| params: [] | |
| }), | |
| pos: pos | |
| }); | |
| } | |
| default: | |
| } | |
| } | |
| for (newField in newFields) | |
| fields.push(newField); | |
| return fields; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment