Last active
August 29, 2015 14:01
-
-
Save postite/120ecca5ab9af1d8f01b 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
class Main | |
{ | |
public function new() | |
{ | |
trace("hello"); | |
var g=new SubOB(); | |
trace(g.pull); | |
g.pull="over"; | |
trace(g.pull); | |
} | |
static public function main() | |
{ | |
var app = new Main(); | |
} | |
} |
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
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
class OBMacros{ | |
public static function macroBuild() { | |
trace( "macrobuild"); | |
var fields = Context.getBuildFields(); | |
var hasManager = false; | |
for( f in fields ) { | |
for( m in f.meta ) | |
switch( m.name ) { | |
case ":postite": | |
trace( "postite meta found"); | |
switch( f.kind ) { | |
case FVar(t, _): | |
trace( "FVar"+t); | |
var pos = f.pos; | |
var ttype = t, tname; | |
trace(pos ); | |
trace( ttype); | |
function e(expr) return { expr : expr, pos : pos }; | |
// i substr( "_") because i don't know how to delete the field or replace it | |
//generate getter | |
var get = { | |
args : [], | |
params : [], | |
ret : t, | |
expr : Context.parse("return untyped "+f.name.substr(1),pos), | |
}; | |
// tried @:noCompletion for fun | |
var meta = [{ name : ":noCompletion", params : [], pos : pos }]; | |
fields.push({ name : "get_"+f.name.substr(1), pos : pos, meta :meta , access : [APrivate], doc : null, kind : FFun(get) }); | |
//generate setter | |
var set = { | |
args : [{ name : "_v", opt : false, type : t, value : null }], | |
params : [], | |
ret : t, | |
expr : Context.parse("return this."+f.name.substr(1)+"=_v",pos), | |
}; | |
//var meta = [{ name : ":hide", params : [], pos : pos }]; | |
var meta = [{ name : ":hide", params : [], pos : pos }]; | |
fields.push({ name : "set_"+f.name.substr(1), pos : pos, meta :meta , access : [APrivate], doc : null, kind : FFun(set) }); | |
//generate (get,set) field | |
var meta = [{ name : ":isVar", params : [], pos : pos }]; | |
var newField = { | |
name: f.name.substr(1), | |
doc: null, | |
meta: meta, | |
access: [APublic], | |
kind: FProp("get","set",macro "polo"), // cannot get the value from _pull eg :'marin' | |
pos: Context.currentPos() | |
}; | |
fields.push(newField); | |
case _: | |
trace( "not a var"); | |
} | |
default: | |
trace( "default"); | |
} | |
switch( f.kind ) { | |
case FVar(t, _): | |
trace("kind="+ t); | |
// if( t != null ) | |
// buildField(f,fields,t,t); | |
default: | |
} | |
} | |
return fields; | |
} | |
} |
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
class SubOB extends OB{ | |
@:postite | |
var _pull:String="marin"; | |
public function new():Void | |
{ | |
trace( "new sub"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment