Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hello;
- import haxe.macro.Context;
- import haxe.macro.Expr;
- /**
- * ...
- * @author Masadow
- */
- class Metadata
- {
- public static var staticRoutes : Array<String> = new Array<String>();
- macro public static function getStaticRoutes() : Expr
- {
- return Context.makeExpr(staticRoutes, Context.currentPos());
- }
- macro public static function test() : Array<Field>
- {
- var fields = Context.getBuildFields();
- var instanceRoutes = new Array<String>();
- var instanceRoutesField : Field;
- for (field in fields)
- {
- for (meta in field.meta)
- {
- if (meta.name == "route")
- {
- //Detect if field is static or not
- var isStatic = false;
- for (access in field.access) if (access == AStatic) isStatic = true;
- //Get the meta param
- switch (meta.params[0].expr)
- {
- case EConst(CString(metavalue)) :
- //Push the value to the corresponding array
- if (isStatic)
- staticRoutes.push(metavalue);
- else
- instanceRoutes.push(metavalue);
- default:
- }
- }
- }
- }
- //Create a field that holds instance routes
- fields.push( {
- access: [APrivate],
- doc: null,
- kind: FVar(macro : Array<String>, Context.makeExpr(instanceRoutes, Context.currentPos())),
- meta: [],
- name: "instanceRoutes",
- pos: Context.currentPos()
- });
- return fields;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement