So either you have to pass an instance of the class to your method, or you have to remove the 'static' keyword.
import haxe.macro.Context;
import haxe.macro.Expr;
class TestMacro {
macro static public function build_some_method() : Array<Field> {
var fields = Context.getBuildFields();
// you can't generate methods, but you can generate class
// and copy it's method to destination class
var c = macro class X {
static public function some_method() {
return Animal.some_method_internal(some_var);
}
};
// extract method we want
var m = Lambda.find(c.fields, function(f) return f.name == "some_method");
// insert into target class
fields.push(m);
// return modified field set
return fields;
}
}
@:autoBuild(TestMacro.build_some_method()) //<< invoke macro for child classes
class Animal {
...
static private function some_method_internal(value : String) { //<< changed to internal private method with parameter passed from macro generated fn
// some needed magic
}
...