Please let me know if you have any good ideas. Thank you.
w = Window.new.front;
w.addToOnClose({ "one".postln });
w.close; // Nothing happens.
w = Window.new.front;
w.onClose = { "one".postln; };
w.close; // It did well.
w = Window.new.front;
w.onClose = { "one".postln; };
a = w.onClose.def.sourceCode
a = a.insert(a.size-1, "\"two\".postln;"); // I want to make SC say one, then two.
w.onClose = a.compile;
w.onClose.def.sourceCode;
w.close; // Nothing happens.
I would use a FunctionList to do so. It is a collection of functions, that you can dynamically increment and decrement. When called, every function within the collection will be evaluated.
See the examples below :
// classic behavior
(
var win = Window().front;
win.onClose = { "1".postln; };
win.close;
)
// same example with FunctionList
(
var win = Window().front;
var onCloseFunction = FunctionList();
onCloseFunction.addFunc({ "1".postln; });
win.onClose = onCloseFunction;
win.close;
)
// now with two functions inside the FunctionList
(
var win = Window().front;
var onCloseFunction = FunctionList();
onCloseFunction.addFunc({ "1".postln; });
win.onClose = onCloseFunction;
onCloseFunction.addFunc({ "2".postln; });
win.close;
)