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. Secure (HTTPS) Sites with WebView

I'm currently working on porting an iPhone app to Android.  It
utilizes the flickr API, so it requires the user to authorize the app
before it can do any actions on behalf of the user.  I'm looking to
use a WebView to accomplish this, as the user needs to navigate to a
particular URL linking their account to an authentication token.

The problem I'm running into is that the URL the user needs to
navigate to is secure, which is not loading in the WebView.  I know
the URL is valid as I can load it up in another browser (Firefox,
Safari, etc.) without any problems.  All other secure URLs I've tried
also have the same behavior.  Non-secure sites load up just fine.

Is there a setting (or settings) for either the WebView, or something
that needs to be placed in the manifest to allow secure sites to load
in the WebView?


2. OutOfMemoryError (external allocation too large for this process)

Hi Experts,

I am beating my head against a wall since 3 days trying to resolve out
of memory exception but still no success.
here is the line giving me this error


everytime when i change the orientation or start this activity again,
it gives me out of memory exception

VM won't let us allocate 6291456 bytes.

it seems i am not leting GC to release my memory.
any solution would be appreciated

3. about YAFFS2 Image

4. Open the mail go to top level income on next day

5. How to compensate for gravity reading in order to calculate velocity

6. Paying $50 for someone to design an application...

7. How can make Calendar in Android relate to my Gmail account?