Lua Game Engine design is a whole topic of discussion on its own. And in one of the coming sessions I God willing plan to cover how Lua engines in entirety work – together with a deep dive into how C# engines (the likes of Unity / MonoGame / etc) also work. But for this specific segment we will just talk about how Lua engines interface with Android.
For this specific article I shall dissect my experience developing an Android Battery Status Extension – available on GitHub for the Open Source Defold Engine as a basis for the discussion. Basically what the extension does, is it allows you to get Battery Charge Percentage and Charging Status from the Android SDK Libraries. To break it down abit here is an Architecture Diagram:
The Lua Runtime is an embed on any Lua Engine that talks directly to C / C++ code. It makes use of a Lua Bridge (employing a technique known as Lua Binding). The mechanics for this is something we can cover in mode detail later on. However, what normally happens is the C / C++ code is normally stuck in between 2 very opinionated worlds: Android and Lua runtime. To talk to Android, it will need to interface with the Java Runtime using a technology known as the Android Native JNI (this is the very stuff of Android NDK).
JNI is a technology that allows C / C++ native code to interact directly to Java Classes. And in the case of the Battery Status Extension, the code is right here.
Needless to say though, all Lua Game Engines that export games to Android use the very same technique. C# Engines on the other side use different techniques altogether, but work in much the same way. I do plan to deep dive into more of Lua engine core as well as C# engine core in a bit more detail in following articles. So stay tuned. More to come.