Created
January 20, 2018 02:37
-
-
Save kevinresol/52600481db02f0e79475adfb4b8fd817 to your computer and use it in GitHub Desktop.
Client side API Wiper for tink_web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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