Languages as Libraries

Selvan
1 min readDec 20, 2020

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,

Lua: Many game engines embed lua for scripting support. There are plenty of examples exist on how to integrate Lua with C/C+.

mruby: Alternative to lua with ruby sysntax. mruby is designed for embedding and using in memory constrained devices.

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 ?

--

--