Skip to content

Interferes with macro #99

@neimanpinchas

Description

@neimanpinchas

Hi, thanks for the wonderfull library.

I tried to use a clone macro in a class that I parse somewhere else but json2object complained, so I ended up to manually copy all fields, line by line.

I tried with @:jignored but didn't help

class Clone {
  public static macro function make_clone_code() {
    var cls = Context.getLocalClass().get().name;
    var fields = Context.getLocalClass().get().fields.get();

    var exprs:Array<Expr> = [];
    exprs.push(macro var temp=$i{"new "+cls+"()"});
    for (f in fields){
        var name=f.name;
        var expr=f.expr;
        exprs.push(macro temp.$name = $i{name});
    }
    exprs.push(macro return temp);
    // Add a clone() method to the class
    
    return macro $b{exprs}
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions