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 18, 2020 15:59
declaration-site unification check
class Point implements UnifyCheck<{x:Int}> {
public var x:Int;
}
class Main {
static function main() {
}
}

--server-connect

Haxe 4.0 introduces a new way of communicating IDE and the compiler.

Here's what an IDE needs to do:

  • start a TCP server on some port (can pass 0 to bind to any available one)
  • start haxe --server-connect <port> where <port> is replaced with the port number the started TCP server was bound to.
  • haxe will connect to that server and await requests, ensure that happens
  • send messages of the following structure:
@nadako
nadako / 1 Main.hx
Last active October 16, 2021 04:38
ocaml-like `with` for Haxe
using WithMacro;
typedef Player = {
final name:String;
final level:Int;
}
class Main {
static function main() {
var player = {name: "Dan", level: 15};
@nadako
nadako / tasks.json
Created August 29, 2016 21:42
tasks.json from Haxe with OCaml problem matcher
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"args": ["ADD_REVISION=1", "-f", "Makefile.win", "haxe"],
"showOutput": "always",
"problemMatcher": {
"fileLocation": "relative",
"owner": "ocaml",
"pattern": [

NOTE: This gist was added to the official building manual and will be updated there from now on: https://haxe.org/documentation/introduction/building-haxe.html

Preparation

  • Uninstall OCaml, MinGW, Cygwin
  • Remove leftover environment vars, cleanup PATH

Installation

// register a build-macro that will be called
// for building fields for subclasses of this class
@:autoBuild(ComponentMacro.build())
class Component {
// this function will be overriden in subclasses
public function registerCallbacks(updates:Array<Void->Void>) {}
}
import haxe.macro.Context;
import haxe.macro.Expr;
class FunctionArgMacro {
macro static function build():Array<Field> {
var fields = Context.getBuildFields();
for (field in fields) {
switch (field.kind) {
case FFun(fun):
var checks = [];
@nadako
nadako / tasks.json
Created April 19, 2016 17:47
haxe problem matcher for vs code
{
"version": "0.1.0",
"command": "haxe",
"args": ["build.hxml"],
"problemMatcher": {
"owner": "haxe",
"pattern": {
"regexp": "^(.+):(\\d+): (?:lines \\d+-(\\d+)|character(?:s (\\d+)-| )(\\d+)) : (?:(Warning) : )?(.*)$",
"file": 1,
"line": 2,
@nadako
nadako / 0_reuse_code.js
Created April 12, 2016 08:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console