From 7c0cb9c69cfc1ae4db90ba074a56d2f7d5ea167f Mon Sep 17 00:00:00 2001 From: Eric Myllyoja Date: Mon, 14 Mar 2022 22:02:44 -0400 Subject: [PATCH] Archiving hookablemacro --- source/funkin/modding/IHook.hx | 1 - source/funkin/util/macro/HookableMacro.hx | 70 ----------------------- 2 files changed, 71 deletions(-) delete mode 100644 source/funkin/util/macro/HookableMacro.hx diff --git a/source/funkin/modding/IHook.hx b/source/funkin/modding/IHook.hx index 66a07ec52..e5e94a3fc 100644 --- a/source/funkin/modding/IHook.hx +++ b/source/funkin/modding/IHook.hx @@ -13,5 +13,4 @@ import polymod.hscript.HScriptable; // ALL of these values are added to ALL scripts in the child classes. context: [FlxG, FlxSprite, Math, Paths, Std] }) -@:autoBuild(funkin.util.macro.HookableMacro.build()) interface IHook extends HScriptable {} diff --git a/source/funkin/util/macro/HookableMacro.hx b/source/funkin/util/macro/HookableMacro.hx deleted file mode 100644 index 967a92cb6..000000000 --- a/source/funkin/util/macro/HookableMacro.hx +++ /dev/null @@ -1,70 +0,0 @@ -package funkin.util.macro; - -import haxe.macro.Context; -import haxe.macro.Expr; - -using Lambda; - -class HookableMacro -{ - /** - * The @:hookable annotation replaces a given function with a variable that contains a function. - * It's still callable, like normal, but now you can also replace the value! Neat! - * - * NOTE: If you receive the following error when making a function use @:hookable: - * `Cannot access this or other member field in variable initialization` - * This is because you need to perform calls and assignments using a static variable referencing the target object. - */ - public static macro function build():Array - { - Context.info('Running HookableMacro...', Context.currentPos()); - - var cls:haxe.macro.Type.ClassType = Context.getLocalClass().get(); - var fields:Array = Context.getBuildFields(); - // Find all fields with @:hookable metadata - for (field in fields) - { - if (field.meta == null) - continue; - var scriptable_meta = field.meta.find(function(m) return m.name == ':hookable'); - if (scriptable_meta != null) - { - Context.info(' @:hookable annotation found on field ${field.name}', Context.currentPos()); - switch (field.kind) - { - case FFun(originalFunc): - // This is the type of the function, like (Int, Int) -> Int - var replFieldTypeRet:ComplexType = originalFunc.ret == null ? Context.toComplexType(Context.getType('Void')) : originalFunc.ret; - var replFieldType:ComplexType = TFunction([for (arg in originalFunc.args) arg.type], replFieldTypeRet); - // This is the expression of the function, i.e. the function body. - - var replFieldExpr:ExprDef = EFunction(FAnonymous, { - ret: originalFunc.ret, - params: originalFunc.params, - args: originalFunc.args, - expr: originalFunc.expr - }); - - var replField:Field = { - name: field.name, - doc: field.doc, - access: field.access, - pos: field.pos, - meta: field.meta, - kind: FVar(replFieldType, { - expr: replFieldExpr, - pos: field.pos - }), - }; - - // Replace the original field with the new field - fields[fields.indexOf(field)] = replField; - default: - Context.error('@:hookable can only be used on functions', field.pos); - } - } - } - - return fields; - } -}