Skip to content

Instantly share code, notes, and snippets.

@Simn
Simn / Main.hx
Created February 19, 2014 18:29
initLocals macro
class Main {
var arg1:Int;
var arg2:String;
var arg3:Bool;
function new(arg1 = 0, arg2 = "foo", arg3 = false) {
MyMacro.initLocals();
}
@Simn
Simn / Main.hx
Created March 5, 2014 12:08
@:generic map copy
class Main {
function new() { }
static function main() {
var intMap = [1 => "foo", 2 => "bar"];
var stringMap = ["foo" => 1, "bar" => 2];
var m1 = new Main();
var m2 = new Main();
var objMap = [m1 => "foo", m2 => "bar"];
@Simn
Simn / DeprecationMacro.hx
Last active August 29, 2015 13:57
Haxe @:deprecated test
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
using haxe.macro.Tools;
using Lambda;
class DeprecationMacro {
/**
@Simn
Simn / LexerGraph.hx
Created March 12, 2014 16:13
LexerGraph for hxparse
import hxparse.Ruleset;
import hxparse.State;
import dot.Graph;
import dot.Node;
import dot.Attribute;
using Lambda;
class LexerGraph<T> {
var graph:Graph;
@Simn
Simn / Fast.hx
Created March 14, 2014 09:25
Haxe abstract + macro Xml fun
import haxe.macro.Expr;
using haxe.macro.Tools;
abstract Fast(Xml) from Xml to Xml {
@:noCompletion public inline function new(xml:Xml) this = xml;
public var name(get,never):String;
inline function get_name() return this.nodeName;
public var elements(get,never):FastIterator;
@Simn
Simn / Main.hx
Created March 18, 2014 19:35
haxe GADT + tuple bug
enum E<T> {
BoolLit(b:Bool):E<Bool>;
IntLit(i:Int):E<Int>;
}
class Main {
static function main() { }
static function sameType<S>(o1:E<S>, o2:E<S>):Bool {
return switch [o1, o2] { // Unmatched patterns: [_,IntLit]
@Simn
Simn / Main.hx
Last active August 29, 2015 13:57
hxtemplo config parsing example
class Main {
public static function main () {
var cfgString = "{
'someValue': ::(values.width-305)/2 + values.height::,
'constantValue': 13
}";
var template = new templo.Template(new haxe.io.StringInput(cfgString));
var values = {
width: 500,
@Simn
Simn / Main.hx
Created March 23, 2014 11:11
Haxe macro custom generator example
class Main {
static function main() {
trace("Hello world");
}
}
@Simn
Simn / Main.hx
Created May 7, 2014 16:48
Tuple<Const>
@:genericBuild(MyMacro.buildTuple())
class Tuple<Const> { }
class Main {
static public function main() {
var t = new Tuple<3>(1, "foo", true);
trace(t.v0);
trace(t.v1);
trace(t.v2);
}
@Simn
Simn / Main.hx
Created May 16, 2014 08:42
collectFields
class Main {
static var fields = MyMacro.buildFieldsArray();
static function main() {
trace(fields); // [x,y,test,fields,main]
}
var x:Int;
var y:String;
function test() {