Tuesday, June 30, 2009

Lua on Java on DalvikVM on Android

Yes, you read that right.

I was poking around with Lua implementations and ran across LuaJ, which is an implementation of Lua written in Java.

Well, after following Davanum Srinivas's instructions on how to convert a standard JAR into one that can be installed in Android, I was able to get it to run Lua scripts inside the Android emulator.

It shouldn't be too hard to write a regular Android application that would allow the user to type in Lua chunks and run them. I haven't seen much in terms of scripting capabilities for the Android platform... Lua would be a good fit for that.

The only caveat is that the LuaJ implementation is generating and running Lua bytecodes in a Lua VM. Which is running on top of the Dalvik VM. So it is going to be crazy slow. It's kind of amazing that it runs at all, Google must have implemented a lot of the core Java stuff, including reflection.

Now here's an interesting tidbit... The Dalvik VM is register based, as opposed to the stack based JVM. And the Lua VM is register based. So what are the possibilities for "native" (by this I mean Dalvik) code generation by the LuaC compiler?

Does the Dalvik VM even support having some memory buffer contain some bytecode that it will then execute? Would we have to go through the filesystem instead (meaning generating a .dex archive or such)? Inquiring minds want to know.

There seems to be a lot of potential in general for a decent scripting language on the Android platform.

1 comment:

Jason said...

Have you had any more progress or experience with this?