Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Chris Angelico
On Mon, May 3, 2021 at 4:25 AM Stephen R. van den Berg wrote: > > Chris Angelico wrote: > >My usual practice is to completely recompile the class, and have a > >single mapping for all "carry-over" state, something like this: > > >And then to replace anything, I'd create a new instance of the >

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Stephen R. van den Berg
Chris Angelico wrote: >My usual practice is to completely recompile the class, and have a >single mapping for all "carry-over" state, something like this: >And then to replace anything, I'd create a new instance of the >newly-compiled class, replace its empty state mapping with the same >one as

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Chris Angelico
On Mon, May 3, 2021 at 3:35 AM Stephen R. van den Berg wrote: > > Lance Dillon wrote: > >The closest I could see is to not really have the functions directly, I > >guess, but an mapping of functions, and overload `() so that it pulls the > >function from the mapping, then you could easily

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Stephen R. van den Berg
Lance Dillon wrote: >The closest I could see is to not really have the functions directly, I guess, >but an mapping of functions, and overload `() so that it pulls the function >from the mapping, then you could easily replace the function by replacing the >reference in the mapping. >The

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Lance Dillon
The closest I could see is to not really have the functions directly, I guess, but an mapping of functions, and overload `() so that it pulls the function from the mapping, then you could easily replace the function by replacing the reference in the mapping. The replaced function would be

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Stephen R. van den Berg
Chris Angelico wrote: >trying to do won't work with injection. But perhaps subclassing can do >what you want - instead of compiling the entire class again, create a >subclass that replaces that one function. Yes, well, that won't cut it, I'm afraid, because I specifically want that function to be

Re: Replacing a single function/method in an existing live class?

2021-05-02 Thread Chris Angelico
On Mon, May 3, 2021 at 2:04 AM Stephen R. van den Berg wrote: > > Say I have this: > > class A { > int k; > void B() { > write("foo %d\n", k); > } > void C() { > k = 3; > write("bar\n"); > } > } > > int main() { > A a = A(); > a->C(); // Displays: bar > a->B();

Replacing a single function/method in an existing live class?

2021-05-02 Thread Stephen R. van den Berg
Say I have this: class A { int k; void B() { write("foo %d\n", k); } void C() { k = 3; write("bar\n"); } } int main() { A a = A(); a->C(); // Displays: bar a->B(); // Displays: foo 3 // At this point I want to replace the function B // in the