Created
August 18, 2016 09:12
-
-
Save skial/592a9c1e58ff701e186de19fae31e946 to your computer and use it in GitHub Desktop.
Sample code for abstract macro question over on the Haxe mailing list - https://groups.google.com/d/msg/haxelang/0IBfsEs3OHg/Hx9DfmDTAwAJ
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
-cp src | |
-debug | |
-main Main | |
--each | |
-js bin/hasString.js |
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
// Generated by Haxe 3.3.0 (git build development @ 6163882) | |
(function () { "use strict"; | |
var Main = function() { | |
console.log(["a","c","b"].toString()); | |
}; | |
Main.main = function() { | |
new Main(); | |
}; | |
Main.main(); | |
})(); | |
//# sourceMappingURL=hasString.js.map |
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
{ | |
"version":3, | |
"file":"hasString.js", | |
"sourceRoot":"file:///", | |
"sources":["C:/dev/macro_abstractHasString/src/Main.hx","C:/dev/macro_abstractHasString/src/MyAbstract.hx"], | |
"names":[], | |
"mappings":";;WAQQ,WACN;AAAA,aC0Be,CA/BD,AAAC,IACD,AAAC,IACD,AAAC;;YDFF,WACb;AAAA;;;;;" | |
} |
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 ; | |
class Main { | |
public static function main() { | |
new Main(); | |
} | |
public function new() { | |
trace( MyAbstract.getAllValues() ); | |
} | |
} |
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 ; | |
@:enum abstract MyAbstract(String) from String to String { | |
public var a = 'a'; | |
public var b = 'c'; | |
public var c = 'b'; | |
public static macro function getAllValues() { | |
var self = haxe.macro.Context.getType('MyAbstract'); | |
var results = []; | |
switch self { | |
case TAbstract(_.get() => ab, params): | |
/*trace( ab ); | |
trace( ab.impl.get() ); | |
trace( ab.impl.get().fields.get() );*/ | |
for (field in ab.impl.get().statics.get()) { | |
switch field.kind { | |
case FVar(_, _): | |
try { | |
var expr = haxe.macro.Context.getTypedExpr( field.expr() ); | |
if (expr != null) results.push( expr ); | |
} catch (e:Dynamic) { | |
} | |
case _: | |
} | |
}; | |
case _: | |
} | |
return macro $a{results}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment