Skip to content

Instantly share code, notes, and snippets.

@back2dos
back2dos / HaxeCompletion.hx
Last active August 29, 2015 13:57
Completion interface
typedef CompletionPoint = {
file:String,
offset:Int
}
interface HaxeCompletion {
function field(at:CompletionPoint):Array<haxe.macro.ClassField>;
function usage(at:CompletionPoint):Array<haxe.macro.Position>;
function toplevel(at:CompletionPoint):Array<TopLevel>;
}
@back2dos
back2dos / Int.hx
Created May 19, 2014 16:58
Strict ints for Oleg.
package strict;
import StdTypes.Int in HxInt;
abstract Int(HxInt) from HxInt to HxInt {
@:op(this + b) inline function add(b:Int):Int return this + (b : HxInt);
@:op(this - b) inline function subtract(b:Int):Int return this - (b : HxInt);
@:op(this * b) inline function multiply(b:Int):Int return this * (b : HxInt);
@:op(this >>> b) inline function urshift(b:Int):Int return this >>> (b : HxInt);
@:op(this >> b) inline function rshift(b:Int):Int return this >> (b : HxInt);
@back2dos
back2dos / Helper.hx
Created May 25, 2014 13:15
Custom indexOf
package ;
class Helper {
static public function indexOf<A>(i:Iterable<A>, filter:A->Bool):Int {
var i = 0;
for (x in a) {
i++;
if (filter(x)) return i;
}
@back2dos
back2dos / Gen.hx
Last active August 29, 2015 14:02
Generate es5 style properties. Use with --macro Gen.use().
package ;
import haxe.macro.*;
import haxe.macro.Type;
using haxe.macro.Tools;
private typedef Accessor = {
name: String,
read: Bool,
abstract Flags(Int) {
public inline function new(i = 0) {
this = i;
}
public inline function has( index : Int ) : Bool {
return this & (1 << index) != 0;
}
var run = true;
Thread.create(function () {
Sys.getChar(true);
run = false;
});
while (run) {
Sys.sleep(.5);
println('yay');//assume this would block until the other side reads in fact
@back2dos
back2dos / UntypedNew.hx
Created November 19, 2014 12:41
Support for untyped new.
package ;
#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.Tools;
#end
@back2dos
back2dos / results.txt
Created January 22, 2015 09:34
Top 100 Haxelibs by download
+-----------+----------------------+
| downloads | name |
+-----------+----------------------+
| 78260 | openfl |
| 57649 | lime |
| 50236 | openfl-samples |
| 49287 | hxcpp |
| 43047 | lime-tools |
| 41134 | openfl-native |
| 40236 | actuate |
@back2dos
back2dos / Main.hx
Created June 1, 2015 07:57
Macro context vs. output context
//Original source code:
class Main {
#if !macro
static function main() {
test();
}
#end
macro static function test() {
@back2dos
back2dos / Main.h
Last active August 29, 2015 14:28
Out args for hxcpp.
#ifndef INCLUDED_Main
#define INCLUDED_Main
#ifndef HXCPP_H
#include <hxcpp.h>
#endif
HX_DECLARE_CLASS0(Main)