I have a little language for live coding made with preProcessor that splits the incoming code and reconstructs it as receiver.method(args). Inside the preProcessor i analyze the code using regexp etc to set these three variables and finally format the string into valid sc code like this:
"%.%(%)".format(receiver, method, args);
I wrote the preProcessor as a class that has an argument for the receving object. However, since the preProcessor returns code that is interpreted outside of the class’ scope the only solution i could think of was to use an environment variable for the receiver. This feels a bit unsafe to me. Is there a better way?
This is (sort of) how i do it now:
MyPreProcessor {
*run {|aReceivingObject|
~receivingObject = aReceivingObject;
thisProcess.interpreter.preProcessor = {|code|
code.split($\n).collect{|line|
var receiver, method, args;
receiver = "~receivingObject";
method = line.findRegexp(...).do{|match| ...};
args = line.findRegexp(...).do{|match| ...};
"%.%(%)".format(receiver, method, args);
}.join;
};
}
}