Last active
December 18, 2015 05:39
-
-
Save jasononeil/5734248 to your computer and use it in GitHub Desktop.
Macro example for EzeQL_ - create ".hx" files at macro time, and then go ahead and use them in your code.
This file contains hidden or 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
-neko Main.hx.n | |
-main Main | |
--macro BuildMacro.build() |
This file contains hidden or 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
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
import sys.FileSystem; | |
import sys.io.File; | |
import haxe.io.Path; | |
class BuildMacro | |
{ | |
static function build() | |
{ | |
var className = "DoesNotExist.hx"; | |
var classDef = "class DoesNotExist { public function new() { trace('Now it does exist'); } }"; | |
addFileToRepo( className, classDef ); | |
return null; | |
} | |
static function addFileToRepo( filename:String, definition:String ) | |
{ | |
// Figure out the path of "Main.hx", and then put our file in the same spot | |
var mainFilePath = FileSystem.fullPath( Context.resolvePath( "Main.hx" ) ); | |
var classFilePath = Path.directory(mainFilePath) + "/" + filename; | |
if ( !FileSystem.exists(classFilePath)) { | |
File.saveContent( classFilePath, definition ); | |
} | |
} | |
} |
This file contains hidden or 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
class Main | |
{ | |
static function main() | |
{ | |
trace ("Haxe!"); | |
new DoesNotExist(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment