Skip to content

Instantly share code, notes, and snippets.

View jasononeil's full-sized avatar

Jason O'Neil jasononeil

View GitHub Profile
@jasononeil
jasononeil / HaxeScript.hx
Created April 22, 2013 06:18
haxex, a short shell script that can be used so you have Haxe shell scripting
#!/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())
@jasononeil
jasononeil / DispatchTest.hx
Last active December 17, 2015 20:19
A sample to test some more complex routing options of haxe.web.Dispatch. Run with `haxe -x DispatchTest.hx` This is the sample code for this tutorial / blog post: http://jasononeil.com.au/2013/05/29/creating-complex-url-routing-schemes-with-haxe-web-dispatch/
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;
@jasononeil
jasononeil / MacroHelpTest.hx
Last active December 18, 2015 03:38
Using a macro as the initialization of one field, and having it base itself on an existing member variable.
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;
@jasononeil
jasononeil / BuildMacro.hx
Last active December 18, 2015 05:39
Macro example for EzeQL_ - create ".hx" files at macro time, and then go ahead and use them in your code.
import haxe.macro.Expr;
import haxe.macro.Context;
import sys.FileSystem;
import sys.io.File;
import haxe.io.Path;
class BuildMacro
{
static function build()
{
@jasononeil
jasononeil / MacroTest.hx
Created June 23, 2013 05:41
Demonstration of blatantly copying fields to a new type not working...
import haxe.macro.Expr;
import haxe.macro.Type;
import haxe.macro.Context;
class MacroTest
{
macro public function build():Array<Field>
{
trace ("Build macro");
@jasononeil
jasononeil / BuildInMacroTests.hx
Created June 24, 2013 07:49
Minimal reproducible test for this error message: /usr/lib/haxe/std/sys/db/Object.hx:29: characters 2-11 : You cannot use @:build inside a macro : make sure that your enum is not used in macro
import haxe.macro.Expr;
import haxe.macro.Context;
import neko.Lib;
class BuildInMacroTests {
public static function main() {
var s:MyModel = new MyModel();
Formatter.__Output_Formatter( s );
}
}
@jasononeil
jasononeil / ArrayAccessTest.hx
Last active December 19, 2015 06:09
Haxe Abstracts: Array Access with different key types representing different functionality
class ArrayAccessTest {
static function main() {
var myArray:MyArray<Int> = [0,10,20];
trace ( myArray[1] );
trace ( myArray["one"] );
trace ( myArray[["one","two","three"]] );
}
}
abstract MyArray<T>(Array<T>) from Array<T> to Array<T> {
@jasononeil
jasononeil / Cast.hx
Last active December 21, 2015 05:29
An Abstract (A) that is Iterable<T> cannot be automatically cast to an Abstract (B) that has a "@:from" cast for Iterable<T>
class Cast
{
static function main()
{
var array = [0,1,2,3];
var list = Lambda.list( array );
var map = [ "a"=>0, "b"=>1, "c"=>2 ];
var stringMap:haxe.ds.StringMap<Int> = map;
var myAbstract:AbstractIterator<Int> = array;
var myAbstract2:AbstractIterator2<Int> = array;
@jasononeil
jasononeil / Mysql.hx
Created August 28, 2013 09:49
Attempt to implement a MySQL class for Haxe Java based on waneck's branch: https://github.com/waneck/haxe/tree/java-sql
package sys.db;
@:coreApi class Mysql {
static var init = false;
/**
Opens a new MySQL connection on the specified path.
Note that you will need a MySQL JDBC driver.
"socket" option currently not supported
@jasononeil
jasononeil / Module1.hx
Created September 6, 2013 02:16
**Compile to separate JS Files in Haxe** In this example 1) SharedCode is compiled to sharedcode.js and must be loaded first 2) Both Module1 and Module2 reference SharedCode, but do not duplicate it's code. Look at the resulting Javascript to see the output. You would have to ensure sharedcode.js is loaded before either of the module javascript …
class Module1
{
static function main() {
SharedCode.greet("Jason");
}
}