Skip to content

Instantly share code, notes, and snippets.

@Simn
Simn / Main.hx
Last active February 22, 2021 09:51
New reification examples
class Main {
static function main() {
MyMacro.testReify();
}
}
package ;
abstract JsonMap<T>({ }) from {} {
public function new() this = {};
public function exists(key:String) return Reflect.hasField(this, key);
@:arrayAccess public function get(key:String) return Reflect.field(this, key);
@:arrayAccess public function set(key:String, value:T):T {
Reflect.setField(this, key, value);
return value;
}
@jdonaldson
jdonaldson / hxn.sh
Last active December 15, 2015 11:49
Simple bash script for switching between haxe nightly and stable
export OLDPATH=$PATH
export HAXE_NIGHTLY=$HOME/bin/haxe_nightly
hxn(){
if [ -z "$USE_HAXE_NIGHTLY" ] || $USE_HAXE_NIGHTLY; then
echo "Changing to Haxe stable version"
export HAXE_STD_PATH=$OLD_HAXE_STD
export PATH=$OLDPATH
export USE_HAXE_NIGHTLY=false
else
echo "Changing to Haxe nightly at: $HAXE_NIGHTLY"
import haxe.macro.Expr;
class FTW
{
public static function build()
{
return haxe.macro.Context.getBuildFields().map(transformField);
}
static function transformField(field:Field)
@nadako
nadako / 1 Main.hx
Created February 18, 2014 22:19
Using haxe macros as syntax-tolerant, position-aware json parser
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.ExprTools;
class Main
{
inline static var QUOTED_FIELD_PREFIX = "@$__hx__";
static function main()
@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;
@nadako
nadako / Main.hx
Last active February 19, 2019 02:07
Tuple builder using new Rest feature of @:genericBuild
class Main {
static function main() {
var a = getValue();
}
static function getValue():Tuple<Bool,Int> {
return new Tuple(true, 10);
}
}
@hamaluik
hamaluik / !Profiler.hx
Last active April 6, 2020 23:11
Simple Haxe Profiler
package ;
import haxe.ds.StringMap;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Printer;
import haxe.macro.Type.ClassType;
import neko.Lib;
using haxe.macro.ExprTools;
@Simn
Simn / Main.hx
Created March 22, 2016 20:52
Simple assert macro that shows sub-expressions
class Main {
static function main() {
var x = 7;
var y = 10;
tools.Assert.assert(x == 7 && y == 11);
}
}
@markknol
markknol / haxe.json
Last active January 28, 2020 18:31
vscode haxe snippets
{
/*
// Place your snippets for Haxe here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// \t, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"Print to console": {
"prefix": "log",
"body": [