Over the last year, I have developed a Crystal shard which allows for using mruby as a scripting language in Crystal projects. Essentially, the shard includes a full mruby interpreter into the app, and also provides macro methods to easily bind Crystal classes and methods to mruby.
Therefore, two powerful programming languages can be combined to compensate both of their most glaring weaknesses.
Anyolite is available here: https://github.com/Anyolite/anyolite, including examples, features, limitations and a documentation of all functions.
Anyolite was designed in a way that scripting support for applications has no major roadblocks and the developer doesn’t need to care about implementation details like coordinating garbage collecting or writing bindings for each single method. Anyolite does support:
- Binding of entire module and class hierarchies with a single line of code
- Keyword arguments and regular arguments
- Structs, enums and unions
- Generic types (as long as all possible types are specified)
- Calling mruby procs from Crystal
- Class inheritance
However, there are still some fundamental differences between Crystal and Ruby which need to be respected:
- Crystal needs to know the type of mruby values at compiletime to convert them
- Arrays and Hashes are only passed as copies (to avoid invalid types)
- Pointers are passed as weak references
- Symbols can not be passed to Crystal
- Splat arguments are not supported
- Only one function argument set can be bound to mruby, so overloading is not directly possible
- Some annotations might be required to give Anyolite additional information
There are still some things I’d like to work on in the future, like:
- Support for the MRI interpreter (this might take some time, though)
- Converting scripts to bytecode at runtime and/or compiletime
- Support for more argument types (like Time, Slice, …), if possible
Currently, Anyolite does explicitly NOT work on Windows and possibly ARM64 (not tested yet) due to a nasty ABI issue (see Issue #9533 ). Any help in dealing with this problem is appreciated.
Anyolite could be used, for example, in game engines (here full Windows support would definitely help), scientific applications or generally to improve the flexibility of Crystal software. As a matter of fact, Anyolite originated from my own plans for a 2D game engine with scripting support and also my experience with implementing scripting in applications.
I want myself and other developers to focus on the actual program instead of wasting hours and hours on the ungrateful task of binding functions to a scripting language - and that’s why I developed Anyolite.