Haxe Code Cookbook

Other

Overview of Haxe other snippets and tutorials.

  • Haxe allows you to add static methods to existing classes (eg. Math) via the static extensions feature. The secret sauce is to specify the first parameter of the extension as Class<X> where X is the class you want to add static methods to (eg. Math), and to make the method public.‥

  • While there is no named parameter support in Haxe, anonymous structures can be used to obtain the same effect.‥

  • Sometimes you find yourself in the need of passing different types to the same parameter of a function. While there isn't a built-in way of doing this in Haxe, thanks to its flexible type system, we can solve this problem. We will explore two ways to achieve this.‥

  • Normally, when compiling Haxe to JavaScript, the resulting code is kept away from the global scope. This means that you can't reach the Haxe generated code from other scripts. To make that possible, there's the @:expose metadata that can be used on a class. This makes the class exposed to the global scope, and therefore possible to use in plain JavaScript.‥

  • This entry came to be after Haxe user anniz shared his experiment which aimed to recreate VGA text rendering in Flash. Soon after, it was proposed and discussed as a potential Code Cookbook entry. You can read more about its history in this repository issue.‥

  • This article is about cppia, a scriptable cpp subtarget for Haxe. A cppia script is a instructions assembly script that can be run inside a cppia host and gives you Neko JIT runtime speed at near-zero compilation time. It also lets add performance critical code to the host, wich gives you full cpp runtime speed for those parts.‥