Skip to content

Instantly share code, notes, and snippets.

View gamedevsam's full-sized avatar

Samuel Batista gamedevsam

View GitHub Profile
@jcward
jcward / Main.hx
Last active September 12, 2020 10:58
Haxe typed compile time constants example macro (parsing or evaluating)
// In a build system, I like to pass typed compile-time constants to my code
// via compiler defines. For example, a host String and a port Int. The
// following macros provide functionality to either parse or eval a compiler
// define as Haxe code. Since they operate at compile time and inject the
// resulting expressions into your code, this retains all type features --
// from type inference to type checking.
//
// Note that $type prints the type at compile time, while trace prints
// the value at runtime. Neko is called simply to demonstrate the latter.
import haxe.macro.Context;
@cwkx
cwkx / doc.txt
Last active March 31, 2019 17:16
HaxeFlixel hscript component system with custom pre-processor in Script.hx
Scripting:
(1) Here is an example script (all one file):
#(init) input, sprite -- An "init" event (runs once) that initializes the "input" and "sprite" packages
Sprite.AddTrail(-1); -- This function is called from the sprite package (without sprite, it will crash)
#(init) controller -- Another "init" event that initializers the "controller" package (so that it can be used in update)
#(update) input, controller -- An "update" event that uses the "input" and "controller" packages
if (Input.Left())
Controller.Move(-100.0);
@nadako
nadako / 1 Main.hx
Created February 18, 2014 22:19
Using haxe macros as syntax-tolerant, position-aware json parser
import haxe.macro.Context;
import haxe.macro.Expr;
using haxe.macro.ExprTools;
class Main
{
inline static var QUOTED_FIELD_PREFIX = "@$__hx__";
static function main()
@nadako
nadako / DynamicMap.hx
Last active January 2, 2016 22:29
Abstract wrapper for Dynamic objects.
/**
* Simple wrapper for anonymous structures that are meant to be used as a
* keyed collection of objects of the same type (i.e. json object).
*
* Wraps Reflect calls with nice syntax and static typing without any
* runtime overhead.
*/
abstract DynamicMap<V>(Dynamic<V>) from Dynamic<V>
{
/**
@dpeek
dpeek / gist:6043433
Created July 20, 2013 01:23
Haxe, Neko and OpenFL on Raspberry Pi
mkdir ~/source
# dependencies
sudo apt-get update
sudo apt-get install libgc-dev bzip2 git-core make gcc g++ gnuplot glade imagemagick libusb-dev python-usb python-lxml python-wxgtk2.8 speech-dispatcher libgnomecanvas2-dev m4 libsdl1.2-dev
# neko
git clone https://github.com/HaxeFoundation/neko.git ~/source/neko
cd ~/source/neko
make
@jgranick
jgranick / gist:1763850
Created February 8, 2012 01:05
NMML File Specification
<?xml version="1.0" encoding="utf-8"?>
<project>
<!-- <meta />
Use meta nodes to set metadata for your application. The description is ignored
on most targets, but is useful for packaging like Chrome Apps or Opera Widgets.
For compatibility with Android and webOS, the package name must include at least