Call a function with an environment

I have classes with member functions described in some way. I want to inject the member functions with a reference to the superclass member function and a reference to self so that I don’t have to put these two parameters in every function in my game.

Right now the only way to do this is by setting the function environment. You can’t clone a function in any way and you can’t call a function with transient data, so if that function gets called again at some point before I have the opportunity to restore its original environment then it will have access to the self and super variables from a previous call.

So what I want is either a function that can call a function in a specific environment, or a function that clones a function so that editing its environment won’t affect subsequent calls to the original.

2 Likes