Skip to content

Instantly share code, notes, and snippets.

@kevinresol
Created January 20, 2018 02:37
Show Gist options
  • Save kevinresol/52600481db02f0e79475adfb4b8fd817 to your computer and use it in GitHub Desktop.
Save kevinresol/52600481db02f0e79475adfb4b8fd817 to your computer and use it in GitHub Desktop.
Client side API Wiper for tink_web
package api;
// to use: add `implements api.Wiper` to your API class
// but it doesn't handle imports, either you use wildcard (import api.*) or guard them with `#if`
#if macro
import haxe.macro.Context;
using tink.MacroApi;
#end
@:autoBuild(api.Wiper.Macro.wipe())
interface Wiper {}
#if macro
class Macro {
public static function wipe() {
var fields = [];
for(field in Context.getBuildFields()) {
if(field.name == 'new') continue;
switch field.kind {
case FFun(func):
if(func.ret == null) field.pos.error('Function return type must be specified');
func.expr = macro throw 'abstract';
case FVar(t, e):
if(t == null) field.pos.error('Member type must be specified');
field.kind = FVar(t, null);
case FProp(g, s, t, e):
if(t == null) field.pos.error('Member type must be specified');
field.kind = FProp(g, s, t, null);
}
fields.push(field);
}
return fields;
}
}
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment