Few light weight languages has support for it’s runtime (virtual machine) to be wrapped as library. This make them embeddable in other language environments.
In the context of iOS/Android, we look at three light weight scripting languages & their runtime which are easy to embed in other languages,
- Javascript
- Lua
- mruby
Javascript: When comes to Javascript embedding for iOS and Android, we have following options,
- Quickjs: — https://bellard.org/quickjs/
- Hermes — https://github.com/facebook/hermes
Lua: Many game engines embed lua for scripting support. There are plenty of examples exist on how to integrate Lua with C/C+.
- Lua — https://www.lua.org/
mruby: Alternative to lua with ruby sysntax. mruby is designed for embedding and using in memory constrained devices.
- mruby — https://github.com/mruby/mruby
Call flow between host and embedded languages:
- Validating function parameters in the host language before being passed to embedded languages
- Bridging type information of the function parameters being passed from host to embeded language.
- Calling the function in embedded language with correct parameter type, value and order.
- Converting return value from embedded language to host language.
- Handle exceptions rasied from embedded language
Integration Challenges:
Integration between host and embedded languages has following challenges,
- Managing type information: Ex- How to handle dynamic typing of embedded environment with static typing of host environment?
- Managing runtime exceptions between host and embedded language.
- Managing concurrency: Ex - How does host “Goroutines” work with embedded Javascript runtime?
- Managing async communication: Ex- How to handle embedded Javascript async execution with host runtime ?