Skip to content

Instantly share code, notes, and snippets.

View nadako's full-sized avatar

Dan Korostelev nadako

View GitHub Profile
@nadako
nadako / Main.hx
Created March 5, 2014 16:03
Haxe for Unity with -net-lib
class Main extends unityengine.MonoBehaviour
{
function Update()
{
unityengine.Debug.Log("Hello");
}
}
import haxe.macro.Context;
import haxe.macro.Expr;
class EnumAbstractMacro
{
public static function build():Array<Field>
{
var fields = Context.getBuildFields();
var values = [];
@nadako
nadako / Main.hx
Created May 5, 2014 12:51
Typed hasField check macro
using TypedFieldMacro;
typedef A = {?f:Int}
class Main
{
static function main()
{
var a:A = {f:1};
if (a.f.exists()) trace(a.f);
@nadako
nadako / Main.hx
Created May 5, 2014 19:12
OptionalField abstract
typedef House =
{
?numTennants:OptionalField<Int>
}
class Main
{
static function main()
{
var house:House = {};
import Reverse.reverse;
class Main
{
static function main()
{
var a = [1,2,3];
for (v in reverse(a))
{
trace(v);
@nadako
nadako / anon.lua
Last active August 29, 2015 14:01
Haxe array & anon in Lua
local Anon_mt = {
__newindex = function(self, key, value)
if value ~= nil then
rawset(self, key, value)
else
self._nils[key] = true
end
end,
__tostring = function(self)
@nadako
nadako / Main.hx
Created May 29, 2014 12:49
Get @:enum abstract values
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.Tools;
@:enum abstract MyEnum(Int) {
var A = 1;
var B = 2;
var C = 3;
}
@nadako
nadako / Main.hx
Last active August 29, 2015 14:02
HXML parser
using StringTools;
typedef Build = {
target:Target,
output:String,
classPaths:Array<String>,
main:String,
debug:Bool,
libs:Array<String>,
defines:Map<String, String>,
@nadako
nadako / Main.hx
Last active August 29, 2015 14:02
CoffeeScript-like destructurize. This is now added to https://github.com/nadako/haxe-thingies repository.
using Unpack;
class Main {
static function main() {
f().unpackInto( [ v1, { a: { length: v2 } }, { a: [ v3, _, v4 ] } ] );
trace(v1); // { a: [ 1 ] }
trace(v2); // 2
trace(v3); // 4
trace(v4); // 5
@nadako
nadako / RuntimeCheck.hx
Created June 9, 2014 19:45
Runtime type check generator.
#if macro
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.Tools;
#end
@:enum abstract MyEnum<T>(T) {}
typedef A = MyEnum<Float>;
typedef B = Array<{a:Int, ?b:Array<{?a:String}>}>;
typedef C = Dynamic<Int>;