More flexibility - inky03/hscript-insanity GitHub Wiki

HscriptInsanity has a small utility class named Patcher with macro functions that can "patch" source code classes. This can help bring more interactivity between source code and scripts!

Patcher.patch(extreme:Bool = false)

An example of how to use this patch...

Compiler.addGlobalMetadata('package', '@:build(insanity.macro.Patcher.patch())')

You can use this feature to patch all calls from Haxe's Type and Reflect classes to HscriptInsanity's implementations of them, as well as Std.isOfType or A is B. This can make source code classes more flexible and able to interact more with scripted types!

You can also pass true as an argument to this build function, which will turn fields and function arguments of Class<T> and Enum<T> types into Dynamics. Be wary as this feature could lead to more unstability and will NOT work on every class, although it can be useful if you want a class in source code to be able to construct a scripted type.

This patch could impact performance, so only use it where you deem useful or necessary!

Patcher.buildHLClass(cls:Class<Dynamic>) (for HashLink)

An example of how to use this patch...

#if hl
@:build(insanity.macro.Patcher.buildHLClass(Math)) class HLMath {}
#end

// note this particular class is already patched and included in insanity by default!! this is only a demonstration

You can build a sort of "proxy" for a HashLink class with this patch, which essentially reimplements a class without the @:hlNative metadata in any applicable fields, which allows Hscript to access them correctly again!

To not affect performance in Haxe compiled code, this macro is supposed to be run on top of an empty class, which must subsequently and ideally be set in Config as a type proxy.

⚠️ **GitHub.com Fallback** ⚠️