Alternative to Beanshell?

Hi guys, Chris from the µManager team here. We’ve discovered a somewhat nasty little bug in Beanshell, that reproduces in both our own interpreter and the one that ships with Fiji. Once you’ve defined a function, you can never again change that function without having to reset the entire interpreter. For example:

void run(i) {print("Hello, " + i);}
void run(i) {print("Goobye, " + i);}
run(0)

This will print Hello, 0; the second declaration of the run function appears to be simply ignored. This gets nasty if you’re trying to e.g. refine a filtering function that you’re using to analyze data.

Beanshell is more or less a dead language; it hasn’t seen serious updates in, I believe, over a decade. I’m not hopeful about trying to keep it alive. However, it might be worth our time to add an alternative scripting language to µManager. What would you guys recommend? Ideally the language would be easily able to work with our custom classes and, of course, would be easy to learn (or even better, already familiar) to our users. Beanshell does great on both of those accounts. Maybe Jython would work out well? How much work do you have to do to get your classes to “cross the language barrier”?

3 Likes

Groovy. It’s basically BeanShell with 1000% more awesome. 99+% compatible with Java syntax. Supports maps and lists in a much more compact way. Etc.

Or if you want to appeal to the many people who have taught themselves Python, then I think Jython is a reasonable second choice.

Both Groovy and Jython support defining Java classes within a script. (See e.g. subclassing Java classes in Jython.) Some other scripting languages can do this as well, including Clojure.

3 Likes

Hi Curtis, thanks for the recommendation! I’m not exactly looking forward to the prospect of updating our current scripting system to support another language, but it’s good to know there’s viable options out there.

Like I said, Groovy is 99+% compatible with Java. So I am guessing updating existing scripts will be extremely straightforward (many may “just work” with no changes).

As for the infrastructural work of updating the plumbing to support another language: might I suggest that embrace the SciJava script framework? That way, you will get support for all SciJava languages for free.

Yeah, it’s mostly a matter of all of our existing infrastructure surrounding Beanshell that will need to be updated, including our own scripting panel, which works a bit differently from the one in ImageJ. Most notably, we include a file editor so you can save/load scripts you’ve produced, but there’s also facilities like being able to specify a script to be run when the program launches, being able to bind scripts to hotkeys and buttons, and so on. If your script framework is anything like the rest of the libraries you’ve produced, I’m confident it can be adapted to our needs; there’s just a lot to be updated. :slight_smile:

1 Like

Sorry for reviving such an old thread, but I was wondering what the status of µManager’s scripting language is at the moment? In our group, we often have the problem that beanshell throws a general error at random points in the code with no way of debugging or protecting against it (often it will say that the error is at the semicolon at the line end). We’ve been considering abandoning beanshell in favor of python, but rewriting 300+ lines of code to fit into a new language is kind of a daunting task when there are always other, more pressing matters :slight_smile:

1 Like

My understanding—which may be wrong—based on a recent conversation I had with @marktsuchida is that µManager still supports only BeanShell right now, but that the goal remains of expanding that to other scripting language(s). So I don’t know that there is much news to report yet on this front.

A little late to this but, thought it’s worth mentioning.

We’ve developed an in-house solution (a plugin) to enable python scripting of micromanager acquisition/analysis. It involves sockets/slots for the IPC, and a variety of methods for data transfer. You just have to create a bridge and then you have access to the Java API from python.

Additionally, micromanager-gamma has recently pulled some similar mechanism that uses strictly zeroMQ for communication and data transfer. It’s a work in progress and has no documentation yet? Also, you’ll have to rewrite your scripts for python-style. Please check the micromanager github here, or henry pinkard’s documentation here

1 Like