Skip to content

Instantly share code, notes, and snippets.

View devboy's full-sized avatar

Dominic Graefen devboy

View GitHub Profile
@devboy
devboy / Lambda.h
Created July 9, 2013 22:23
lambda macro
#define _lambda_param(index, ARG) id ARG,
#define _lambda_last_param(arg) id arg
#define _lambda_1_(statement) ^id(){ return statement; }
#define _lambda_2_(arg, statement) ^id(id arg){ return statement; }
#define _lambda_gt2_(...) ^id( metamacro_foreach( \
_lambda_param,,metamacro_take(metamacro_dec(metamacro_dec(metamacro_argcount(__VA_ARGS__))), __VA_ARGS__)) \
_lambda_last_param(metamacro_at(metamacro_dec(metamacro_dec(metamacro_argcount(__VA_ARGS__))), __VA_ARGS__)) \
){ return metamacro_at(metamacro_dec(metamacro_argcount(__VA_ARGS__)), __VA_ARGS__); }
#define lambda(...) \
@devboy
devboy / HaxeTest.hx
Created April 6, 2012 23:28
haXe WTF?
class A
{
}
class B extends A
{
}
class HaxeTest
{
@devboy
devboy / Rakefile.rb
Created February 17, 2012 08:01
haXe organize imports
HXML = ENV["hxml"]
module TextFileUtil
attr_accessor :file
def file_lines
File.open(@file).readlines
end
def file_dir
File.dirname @file
end
package org.devboy.hxTask;
import neko.Lib;
import haxe.macro.Context;
import haxe.macro.Expr;
import haxe.macro.Type;
class ComponentMacro
{
private static var idCount = 0;
#
# Copyright (C) 2011 by Dominic Graefen / http://devboy.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
var doMath = function( x: Int, y: Int, operation: Int->Int->Int )
{
return operation( x, y);
}
Lib.println( doMath( 10, 20, Funk.d( _ * _ ) ) ); // 200
//Lib.println( doMath( 10, 2, Funk.d( _ / _ ) ) ); // error because of int float issues
Lib.println( doMath( 10, 20, Funk.d( _ + _ ) ) ); // 30
Lib.println( doMath( 10, 20, Funk.d( _ - _ ) ) ); // -10
var point: { x: Int, y: Int };
var pointA3D: { x: Int, y: Int, z: Int } = { x:10, y:10, z:10 };
var pointB3D = { x:10, y:10, z:10 };
point = pointA3D; // this works fine, as the type is set
point = pointB3D; // error: { z : Int, y : Int, x : Int } has extra field z
point = { x:10, y:10, z:10 }; // { z : Int, y : Int, x : Int } has extra field z
var circle: { x: Int, y: Int, radius: Int } = { x: 10, y: 10, radius: 10 };
var rect: { x: Int, y: Int, width: Int, height: Int } = { x: 20, y: 20, width: 100, height: 100 };
function move( objectWithXAndY: { x: Int, y: Int } )
{
objectWithXAndY.x += 5;
objectWithXAndY.y += 5;
}
move( circle );
typedef Position = { x: Float, y: Float };
var point: Position = new Point(10, 10);
var point: { x: Float, y: Float } = new Point(10,10);