Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import haxe.macro.Context;
- import haxe.macro.Expr;
- class TestMacro {
- static var allFields = [];
- public macro static function generateClass()
- {
- var c = macro class MyClass {
- public function new() { }
- }
- for(field in allFields)
- {
- c.fields.push({
- name: field.name,
- doc: null,
- meta: [],
- access: [APublic],
- kind: FVar(field.type, null),
- pos: Context.currentPos()
- });
- }
- haxe.macro.Context.defineType(c);
- return macro null;
- }
- macro static public function build():Array<Field> {
- var fields = Context.getBuildFields();
- for (field in fields)
- {
- switch (field.kind)
- {
- case FVar(type, _):
- switch (type)
- {
- case TPath(path):
- allFields.push({name:field.name,type:type});
- default:
- }
- default:
- }
- }
- return fields;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement