HaxeFoundation / HaxeManual

The official Haxe manual
https://haxe.org/manual/
Creative Commons Attribution 4.0 International
218 stars 154 forks source link

Document Class Shadowing #541

Open AdamHarte opened 6 days ago

AdamHarte commented 6 days ago

Explanation from the Haxe Discord:

shadow Shadowing classes in haxe, means, overwriting an original source file with a local copy without needing to modify the original copy.

This is useful under situations where you want to test out changes to libraries, or change something to fit your projects needs.

1) Locate the full package of the file you wish to overwrite as an example - flixel/system/frontEnds/SoundFrontEnd.hx 2) Go to your own project and locate your source directory. Create a file called SoundFrontEnd.hx at the exact same destination. So it looks a little like: your_project_root/src/flixel/system/frontEnds/SoundFrontEnd.hx 3) Copy the contents of the original file (or a pr) to the file created within your project 4) You've now overwritten the original source file! Make any changes you wish to this file and it will apply to all SoundFrontEnd references, including inside libraries.

Notes: it's even possible with a lib, as long as -lib newImplem is later than -lib oldImplem in hxml order

It replaces the entire file, but it is possible to replace specific vars and functions using a macro, if that is actually what you want.