blob: 118f0e8f82f7dd224cf49967dd8e058cf3c674a3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
package utils.macro;
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.Tools;
class Macro {
macro public static function getTypedObject(obj:Expr, typePath:Expr):Expr {
final type = Context.getType(typePath.toString());
switch (type.follow()) {
case TAnonymous(_.get() => td):
final name = obj.toString();
if (obj.expr.match(EObjectDecl(_))) {
throw new Error('$name should be passed as reference (inside of variable)', obj.pos);
}
final e:Expr = {
expr: EObjectDecl([
for (field in td.fields) {
field: field.name,
expr: macro $p{['$name', '${field.name}']},
}
]),
pos: Context.currentPos()
}
return e;
default:
throw new Error(type.toString() + " should be typedef structure", typePath.pos);
}
}
macro public static function getBuildTime():Expr {
return macro $v{Date.now().toString()};
}
}
|