Skip to content

Instantly share code, notes, and snippets.

@francescoagati
francescoagati / machine.js
Created December 28, 2020 09:48
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import haxe.macro.Expr;
import haxe.macro.Context;
using haxe.macro.ExprTools;
using haxe.macro.MacroStringTools;
class FunctionThread {
public static macro function thread(exprs:Array<Expr>) {
var exprs = [ for (expr in exprs) macro var _ = $expr ];
@francescoagati
francescoagati / EventHandler.hx
Created August 15, 2016 14:12
haxe 3.3 handling events with abstracts resolve macro and inlining objects
import haxe.macro.Expr;
#if macro
import haxe.macro.Context;
using tink.MacroApi;
using haxe.macro.ExprTools;
using haxe.macro.Context;
#end
#if !macro
@francescoagati
francescoagati / EventHandler.hx
Created August 15, 2016 14:11
haxe 3.3 handling events with abstracts resolve macro and inlining objects
import haxe.macro.Expr;
#if macro
import haxe.macro.Context;
using tink.MacroApi;
using haxe.macro.ExprTools;
using haxe.macro.Context;
#end
#if !macro
@francescoagati
francescoagati / FunctionThread.hx
Created August 11, 2016 10:05
Function threading with macro inspired from clojure
import haxe.macro.Expr;
import haxe.macro.Context;
using haxe.macro.ExprTools;
using haxe.macro.MacroStringTools;
class FunctionThread {
public static macro function thread(exprs:Array<Expr>) {
var exprs = [ for (expr in exprs) macro var _ = $expr ];
class Getter<T> {
var filter:String;
var obj:Array<T>;
public inline function new(obj:Array<T>,filter:String) {
this.filter = filter;
this.obj = obj;
}
public inline function get(value:Dynamic) {
var new_list:Array<T> = [];
@francescoagati
francescoagati / Main.hx
Created June 14, 2016 19:09
haxe nested structInit
@:structInit
class A {
var x:Int;
var y:Int;
}
@:structInit
class B {
var a:A;
var k:Int;
@francescoagati
francescoagati / Main.hx
Created June 14, 2016 00:06
haxe abstract and inline objects
class Getter<T> {
var name:String;
var obj:T;
public inline function new(name:String,obj:T) {
this.name = name;
this.obj = obj;
}
public inline function get() return untyped (obj:haxe.DynamicAccess<Dynamic>)[name];
@francescoagati
francescoagati / index.js
Created May 18, 2016 08:33
requirebin sketch
'use strict';
var snabbdom = require('snabbdom');
var patch = snabbdom.init([require('snabbdom/modules/class'),
require('snabbdom/modules/props'),
require('snabbdom/modules/style'),
require('snabbdom/modules/eventlisteners')]);
var h = require('snabbdom/h.js');
var vnode;
@francescoagati
francescoagati / Main.hx
Created November 26, 2015 00:41
import yaml in haxe at compile time
#if macro
import yaml.Yaml;
import yaml.Parser;
import yaml.Renderer;
import yaml.util.ObjectMap;
import haxe.macro.Context;
#end
class Main {