Skip to content

Instantly share code, notes, and snippets.

@ibilon
ibilon / GenNew.hx
Last active February 23, 2016 12:13
Object construction with macro
import haxe.macro.Expr;
import haxe.macro.Context;
class GenNew
{
macro public static function build () : Array<Field>
{
var fields = Context.getBuildFields();
var args = [];
var assigns = [];
@ibilon
ibilon / dep_solve.cpp
Created March 11, 2016 22:30
Dependency resolution
#include <fstream>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <vector>
#include "constraint_solver/constraint_solver.h"
// Unzip https://github.com/google/or-tools/releases/tag/v2015-12 next to this file
@ibilon
ibilon / Host.hx
Last active January 2, 2018 12:06
Calling hxcpp app from c++ app
// haxe -main Host -cpp host
// ./host/Host ./lib/Main.dso
class Host {
public static function main () {
var lib = Dl.open(Sys.args()[0], Dl.RTLD_NOW);
if (lib == null) {
trace("can't find library");
Sys.exit(1);
}
import haxe.macro.Context;
#if !macro
@:genericBuild(GenericClass.build())
#end
class GenericClass<@:const Content> {
public static function build () {
return switch (Context.getLocalType())
{
case TInst(_, [TInst(_.get() => { kind: KExpr(macro $v{(s:String)}) }, _)]):
@ibilon
ibilon / Table.hx
Created June 7, 2017 06:46
Wrapper around lua.Table with from function for array and map
package luautils;
import lua.Lua;
import lua.Table in LuaTable;
abstract Table<K, V> (LuaTable<K, V>) from LuaTable<K, V>
{
function new (table:LuaTable<K, V>) this = table;
@:from static function fromMap<K, V> (map:Map<K, V>) : Table<K, V>
@ibilon
ibilon / Test.hx
Last active August 25, 2018 14:29
using Test;
class Test {
var A (default, never): Int = 1;
public function new() {
}
public function set(value:Int) {
trace(value);
@ibilon
ibilon / Main.hx
Last active January 28, 2021 11:31
Haxe compile time json
class Main {
macro static function compileJson(path:String) {
return haxe.macro.Context.parseInlineString(sys.io.File.getContent(path), haxe.macro.Context.currentPos());
}
static function main() {
final a = compileJson("test.json");
trace(a);
a.obj.sub += 1;
trace(a);