Playing Around - Lua Scripting on Android & Performance

by kristianlm » Mon, 09 Aug 2010 11:00:46 GMT

Sponsored Links

As I was recently looking into a scripting language feasable for
Android. Scripting in this context means having your android-app
execute parsed code, like if you want user-supplied AI scripts in your

There exists a scripting-layer implemented at ,
but the popular language Lua seems to not be supported.

So I went ahead and put Lua's Java-port into my android-project and
gave it a try. Performance is of course slow compared to a computer,
but I think it's still very exciting to have the functionality into my
games. A quick a rough performance estimation:

lua, c/c++, desktop:           18ms
luaj, java, dekstop:           180ms
kahlua,java,desktop:        219ms
luaj,java(dalvik), HTC desire,2000ms

*Note* that time elapsed includes parsing & compilation-time.

My LuaJ that goes into my android-project is 240k, but this can
probably be stripped of a lot of things (like the lua console).

The test-script i used was:

-- mytest.lua
-- ---------
function isprime(n)
        if n % 2 == 0 then
                return false
    for i = 3, math.sqrt(n), 2 do
        if n % i == 0 then
            return false
    return true

x = 999999919

for i = x, x + 100, 2 do
        if isprime(i) then
                print(string.format("%17s is prime", i))

-- -------------

Also, I have an idea on performance improvement, but lack knowledge of
Groovy & Dalvik, and it's a little "out-there".

If I have understood Groovy ( 
%28programming_language%29) correctly, it takes it's code and
makes .class files which can be run from Java? If we could run convert
such class-files to dex  dynamically, and run them, would we not get
much better perfomance? specially with JIT on android 2.2 perhaps?

Could this be even possible?

Anyway, have fun with Lua,


Playing Around - Lua Scripting on Android & Performance

by Chunlin Zhang » Tue, 10 Aug 2010 09:52:12 GMT


AFAIK,Lua is the first language android-scripting(now SL4A)
implemented.Have you ever try it?


Sponsored Links

Other Threads

1. Nx1 (2nd

Thanks All ;)  SOL

2. My app is missing in HTC tattoo market

Hi, I have postet an app in market, which doesn't show up in HTC
In the manifest I have the following:

 <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="5" />
        <supports-screens android:largeScreens="true"
android:normalScreens="true" android:smallScreens="true"
android:anyDensity="true" />

but still it doesn't show. Does anyone have an idea about what could
be wrong

3. how to verify whether an application is lauched or not

4. setContentView fails when creating a new activity

5. communication between android phone and pc using 3G network

6. OutOfMemory Error (Animation)

7. Getting "some" of the Android source