larsiusprime / polymod

Atomic modding framework for Haxe
MIT License
159 stars 60 forks source link

[BUG] Calling another function in the same Scripted class clears the local scope #124

Closed EliteMasterEric closed 2 years ago

EliteMasterEric commented 2 years ago

Example:

class Module extends SomeOtherThing {
    function functionB(value:Int) {
        var test4 = value * 3 - 2
        return test4;
    }
    function functionA(test:Int) {
        var test2 = test * 2;

        var test3 = functionB(test2);

        trace(test2); // This fails when it shouldn't.
        trace(test4); // This works when it shouldn't.
    }
}

Root cause: When the interpreter calls this.functionB(), it reuses the Interp object as used by functionA and overrides its state as it does so. The local state needs to be preserved before the function call and restored afterwards.

EliteMasterEric commented 2 years ago

Fixed by cd4600c.