Skip to content

Instantly share code, notes, and snippets.

@leshido leshido/Hacky.hx
Created Feb 2, 2019

What would you like to do?
A hacky way to hijack methods in the Haxe standard library
--macro haxe.macro.Compiler.addMetadata("@:build(", "Math")
# Replace 'Math' with any class that you intend to hijack
import haxe.macro.*;
class Hacky {
public static function build() {
var fields = Context.getBuildFields();
for (field in fields) {
if ( == "random") { // Here we target the `random()` method of the Math class.
return fields;
class Main {
public static function main() {
private static function __init__() : Void {
Math.random = function() {
// custom PRNG code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.