Examining how Lua Game Engines work with Android

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.

Published by Ahmed Maawy

Ahmed Mohamed Maawy is a seasoned technologist with over a decade of experience growing and leading technology products across the African continent - Currently the VP for Engineering at Streamlytics. In his role as VP of Engineering at Streamlytics he leads engineering product development for both B2C and B2B products. Prior to Streamlytics his work spanned leading engineering at Griffin Kenya (an InsureTech Company) as the Chief Technology Officer to working for innovative and disruptive startups like EveryLayer Broadband, Ushahidi, and one of Time's Magazine 50 most genius companies BRCK; the only company in East Africa that designs its own complete hardware and software stack. Most recently he was at the Al Jazeera Media Network, working on both Digital & Broadcast technical integrations. He was part of the team that launched Al Jazeera’s streaming service AJ+ and was heavily involved in the organization's Media Archive Artificial Intelligence projects. Ahmed is a respected leader and pioneer in the Kenyan technology community, his work having been featured in Quartz Magazine, Fast Company & Huffington Post. He sits on the advisory board for CIO’s East African leading Internet of Things and Artificial Intelligence conference, the East Africa IoT and AI Summit.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: