The Crystal Programming Language Forum

How to make crystal app scriptable?

Is there some simple possibility to make crystal app scriptable? Main points:

  • allow users to script the GUI application
  • some sort of scriptable config files (it is often possible to use python expressions in the python app config files)
  • syntax? something very simple and powerful (why not like crystal/ruby)
  • ability to communicate with objects from the main crystal application

Any ideas? Thanks!

You could use a embeddable language like Lua.

Lua is frequently used in the way you describe.
You could also check out cruby (ruby-c?) and there are others too, but Lua feels like the most common.

“How to make a crystal app scriptable” is already implying it’s a crystal app, right?

You mean like maybe how to embed Crystal into C++ or other languages?

I can’t give input (not knowledgeable enough), but I’m sure other devs can chime in

I need to embed some simple scripting abilities (with object support) to the Crystal app. I don’t like lua much - some sort of Crystal mini interpreter (written in Crystal) would be ideal :)

I have experimented with a basic “interpreter”, similar to Ruby’s Object#send (https://github.com/j8r/crystal-object-send). It is quite limited, I don’t think it will fit your use case.
Note that all method arguments have to be typed for the internal casting.

1 Like

crinja is a template engine, but it has a very powerful expression evaluation and integrates deeply with Crystal types.
The jinja syntax is somewhat usable for app scripting (for example ansible uses it for customization). But it would probably be not too difficult to hook up a parser for a different syntax that’s better suited for this use case.

Apart from that, you can embed different scripting languages into Crystal, for example lua, mruby, python or javascript. There should be shards available.

1 Like