Extending Haxe classes in Hscript - inky03/hscript-insanity GitHub Wiki
To make Haxe classes extendable for scripting, run Compiler.addGlobalMetadata('', '@:build(insanity.macro.ScriptableMacro.buildScriptable(["exclude"], ["unless"]))')!
The first array will exclude any classes from being injected, the second array will unexclude them, and you can pass a function on the third parameter for further filtering, if you need to cherry pick. Theres 2 additional boolean parameters after that also allow you to perform more risky injection (see documentation) if so desired.
You can get a map with every scriptable class in insanity.backend.types.Scripted.ScriptedTools.scriptableClasses.
What if I don't want scripted classes?
You can now add the insanity.noScriptableTypes define to disable scripted classes and types entirely!
Limitations
- The following classes can't be injected..
- Extern classes
- Internal (like, Haxe / target specific classes and HscriptInsanity's) classes
- Classes with
@:coreApi,@:hlNative,@:nativemetadata
- If you attempt to extend a class that wasn't injected, the error "Class [class name] can't be extended for scripting" will be thrown.
- This build macro should be added to every class and not filtered with
Compiler.addGlobalMetadata, as that may cause the compiler to fail (the macro expects superclasses to have been injected to work). You can use the first two parameters to filter classes as aforementioned.