[Breaking Change] Rename init and make it not use the super constructor arguments#286
Conversation
init to not use the super constructor argumentsinit to not use the super constructor arguments
6fcef7f to
cfd8052
Compare
EliteMasterEric
left a comment
There was a problem hiding this comment.
Aside from the change I linked, since you're making a potentially breaking change here and adding backwards compatibility for it anyway, it would be nice to implement #241 and rename init to scriptInit for consistency with the other generated methods.
init to not use the super constructor argumentsinit and make it not use the super constructor arguments
cfd8052 to
6d9ef90
Compare
|
All done, though now that the function has received a new name it surely is a breaking change for existing Haxe code that used |
6d9ef90 to
335825c
Compare
The function: * Has now been renamed to `scriptInit`. * Will now take an arbitrary amount of arguments instead of copying the super class constructor.
335825c to
1ce3b95
Compare
|
I want to test and merge this, it'll take a PR on the Funkin' side though. Notably, internally I already made a PR to optimize out all the |
Resolves #241
HScriptedClass.initis pretty odd because it's used throughout FNF as the equivalent ofnewfor script classes, but it accepts the super class's constructor arguments as its own, and then initializes an instance of the script class using those arguments, however a script class is actually independent from the super class in this regard and can have any arguments it wants, which may not be the same the super class has. When scripts use it, it causes issues in some targets, where some of the arguments either get converted incorrectly, become null or, on HashLink, throws an error about the incompatible type.One instance of that in FNF is
phillyTrain.hxc, which instantiates an instance ofBuildingEffectShaderwithScriptedFlxRuntimeShader.init('BuildingEffectShader', 1.0), which calls aninitof arguments (Null<String>, Null<String>, Null<String>), it works fine on C++ since there is no type-checking, but on HL it throws an error about being unable to cast a float to a string. This is not a mistake on the script's end, since it does accept a float as its argument.So I've made it use haxe.Rest for the arguments, however since it doesn't work well with Reflect I had to add some backwards compatibility handling for scripts using it.
The registries and other parts of Haxe code that call
initseem to work well with these changes somehow, but I recommend caution regarding any breaking changes this could introduce.