This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
class F | |
{ | |
macro public static function f(a : Expr, b : Int) : Expr | |
{ | |
// get the field name as a string, use Pattern Matching or tink macros probably... | |
var fieldName = switch (a.expr) { | |
case EConst(CIdent(name)): name; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.ds.StringMap; | |
import haxe.web.Dispatch; | |
import haxe.web.Dispatch.DispatchError; | |
#if sys | |
import Sys.println; | |
import Sys.print; | |
#else | |
import haxe.Log.trace in println; | |
import haxe.Log.trace in print; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/haxex | |
// Run with "./HaxeScript.hx some args here" | |
class HaxeScript | |
{ | |
public static function main() | |
{ | |
trace('Hi, the following ${Sys.args().length} arguments were passed in:'); | |
for (a in Sys.args()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.macro.Expr; | |
import haxe.macro.Context; | |
class ClassicSwitch | |
{ | |
macro static public function from(inExpr:Expr):Expr | |
{ | |
var retExpr:Expr = null; | |
switch (inExpr.expr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys.db.Types; | |
using Lambda; | |
/** | |
* What this class shows: | |
* | |
* Using a custom serialiser for SPOD can reduce speeds by more than half. | |
* Have a build macro append a static array containing the names of the fields to serialise. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile with: haxe -main WebSocketTest.hx -js WebSocketTest.js | |
// Doing your imports like this makes it much easier to port with existing Javascript code. | |
import js.Browser.window; | |
import js.Browser.document; | |
import js.html.*; | |
class WebSocketTest | |
{ | |
static var wsUri = "ws://echo.websocket.org/"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Macro Compiler Define example | |
* | |
* Shows how to use a compiler configuration macro to set up more "defines" based | |
* on an existing define. | |
* | |
* Jason O'Neil 2013. Use as you please. | |
* | |
* haxe -D mydebug --macro "MacroDefine.setDefines()" -x MacroDefine.hx | |
* -- traces "A" and "B" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Detox; | |
public class DOMReady | |
{ | |
static function main() | |
{ | |
Detox.ready(function (e) { | |
Detox.document.title = "Page is ready"; | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Only tested on Neko, Haxe3RC | |
// Compile and run with: | |
// haxe -x InitialisationChecker.hx | |
// Created by Jason O'Neil, 2013. Release public domain. | |
#if macro | |
import haxe.macro.Context; | |
using Lambda; | |
#end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.macro.Context; | |
import haxe.macro.Expr; | |
class Builder { | |
// Build macros are called using @:build() or @:autoBuild() metadata | |
// They must return an array containing all of the fields of the new type | |
macro static function build():Array<Field> { | |
// Create expression representing the test() function | |
var funcExpr = macro function():String { | |
return "test"; |