Skip to content

Instantly share code, notes, and snippets.

@sonygod
Created January 27, 2021 07:18
Show Gist options
  • Select an option

  • Save sonygod/58ef4c39ab8f99e8526d4eee5c1ad2be to your computer and use it in GitHub Desktop.

Select an option

Save sonygod/58ef4c39ab8f99e8526d4eee5c1ad2be to your computer and use it in GitHub Desktop.
macro error
import haxe.macro.Expr;
import haxe.macro.Context;
@:remove @:autoBuild(GenIDIM.addID())
extern interface GenID {}
class GenIDIM {
public static function addID():Array<Field> {
var fields:Array<Field> = Context.getBuildFields();
var idField:Field = {
name: "_id",
doc: null,
meta: [],
access: [AStatic, APrivate],
kind: FVar(macro:Int, macro -1),
pos: Context.currentPos()
};
var getIdField:Field = {
name: "getID",
doc: "fuck",
meta: [],
access: [AStatic, APublic],
kind: FFun({
params: [],
args: [],
expr: macro {
if (_id == -1) {
_id = 0;
}
return _id;
},
ret: macro:Int
}),
pos: Context.currentPos()
};
fields.push(idField);
fields.push(getIdField);
return fields;
}
}
@sonygod
Copy link
Copy Markdown
Author

sonygod commented Jan 27, 2021

genMain

import haxe.macro.Context;
import haxe.macro.Expr;

@:remove @:autoBuild(GenMainBuild.buildFields())
extern interface GenMain {

}

class GenMainBuild {
macro public static function buildFields():Array {
var fields:Array = Context.getBuildFields();
var cls = Context.getLocalClass().get();
var pack = cls.pack.concat([cls.name]);
var name = pack.join(".");

    var  typePath:TypePath={pack: cls.pack,name:cls.name};


    fields=fields.concat((macro class {

        public static function main(){
            new $typePath();
        }
    }).fields);
    return fields;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment