Skip to content

Instantly share code, notes, and snippets.

@back2dos
back2dos / Manual.hx
Created April 25, 2013 15:49
Manually manage memory with a pool.
package ;
class Manual {
static var pool = [];
static var check = new Map<Manual, Manual>();
var count:Int = 0;
function new() {}
function init() {/*set up*/}
function free() {/*clean up*/}
@back2dos
back2dos / Main.hx
Created May 1, 2013 16:09
ECheckType and implicit conversion issue, haxe r6518
package ;
abstract MyAbstract(Int) {
public function new(v:Int) this = v;
@:from static function fromString(s:String) return new MyAbstract(Std.parseInt(s));
}
class Main {
#if !macro
static function main() {
var d:Dynamic = test();
@back2dos
back2dos / Build.hx
Last active December 19, 2015 13:48
Store build information in metadata.
package ;
import haxe.rtti.Meta;
typedef BuildInfo = {
date: Date,
}
class Build {
static public var info(get, null):BuildInfo;
static function get_info() {
@back2dos
back2dos / Animals.hx
Created July 27, 2013 09:37
Fun with abstracts: grouping members without overhead.
package ;
abstract Animals(ExampleData) from ExampleData {
public var dog(get, never):Animal;
inline function get_dog():Animal return this.dog;
public var cat(get, never):Animal;
inline function get_cat():Animal return this.cat;
public var cow(get, never):Animal;
@back2dos
back2dos / Main.hx
Last active December 20, 2015 12:09
package ;
class Main {
static function main() test(Foo);
static function test(e:MyEnum) {}
static function test2():MyEnum
return Foo;
}
package ;
import Map;
import cpp.vm.Mutex;
abstract ThreadSafeMap<K, V>({ data: IMap<K, V>, lock: Mutex }) {
public function new(data:IMap<K, V>)
this = { data: data, lock: new Mutex() }
@back2dos
back2dos / example.js
Last active December 21, 2015 22:39
Scoped routers.
function wrapRouter(addRoute, basicFunctionality) {
return {
register: function (rule, handler) {
require("util").inherits(handler, basicFunctionality);
var factory = function (req, res) {
this.request = req;
this.response = res;
};
factory.prototype = handler;
addRoute(rule, function (req, res) {
@back2dos
back2dos / Module.hx
Last active December 22, 2015 11:19
Compile only classes belonging to a given module
package ;
import haxe.macro.Type;
import haxe.macro.Expr;
import haxe.macro.Context;
class Module {
static function build(?module:String) {
function isIncluded(meta:MetaAccess)
@back2dos
back2dos / Main.hx
Created September 13, 2013 11:50
Fun with chains.
package ;
using Main;
typedef Future<T> = (T->Void)->Void;
typedef Chain<T> = Future<Option<{ data: T, next: Chain<T>}>>;
class Main {
static function lazy<A>(g:Void->A) {
var done = false,
@back2dos
back2dos / Signal.hx
Last active December 23, 2015 09:19
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
#end
abstract Signal<T>(Array<T>)
{
public inline function new()
{
this = [];