Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7915293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:24:35+00:00 2026-06-03T14:24:35+00:00

I’m developing an Android game in Java which uses Lua scripts. To execute these

  • 0

I’m developing an Android game in Java which uses Lua scripts. To execute these scripts, I’m using LuaJ with Java’s ScriptEngine class. For example…

ScriptEngineManager sem = new ScriptEngineManager();
scriptEngine = sem.getEngineByExtension(".lua");
script = ((Compilable)scriptEngine).compile("some lua here");

However, this is apparently not supported on Android (something to do with android not having a full blown JVM, I read somewhere). Is there a way I can use Lua scripts on Android? Maybe there’s a LuaJ alternative? Perhaps there is a way of compiling and executing Lua scripts using LuaJ directly (though I can’t see how).

FYI, I see this error when I try to run this code on Android:

05-06 16:12:32.870: E/dalvikvm(17509): Could not find class 'javax.script.ScriptEngineManager', referenced from method unearth.levels.LevelReader.<init>
05-06 16:12:32.870: W/dalvikvm(17509): VFY: unable to resolve new-instance 787 (Ljavax/script/ScriptEngineManager;) in Lunearth/levels/LevelReader;
05-06 16:12:32.870: D/dalvikvm(17509): VFY: replacing opcode 0x22 at 0x0018
05-06 16:12:32.875: E/dalvikvm(17509): Could not find class 'javax.script.Compilable', referenced from method unearth.levels.LevelReader.parseScript
05-06 16:12:32.875: W/dalvikvm(17509): VFY: unable to resolve check-cast 782 (Ljavax/script/Compilable;) in Lunearth/levels/LevelReader;
05-06 16:12:32.875: D/dalvikvm(17509): VFY: replacing opcode 0x1f at 0x0047
05-06 16:12:32.875: W/dalvikvm(17509): VFY: unable to resolve exception class 788 (Ljavax/script/ScriptException;)
05-06 16:12:32.875: W/dalvikvm(17509): VFY: unable to find exception handler at addr 0x51
05-06 16:12:32.875: W/dalvikvm(17509): VFY:  rejected Lunearth/levels/LevelReader;.parseScript (Lorg/w3c/dom/Element;Lunearth/levels/Level;)V
05-06 16:12:32.875: W/dalvikvm(17509): VFY:  rejecting opcode 0x0d at 0x0051
05-06 16:12:32.875: W/dalvikvm(17509): VFY:  rejected Lunearth/levels/LevelReader;.parseScript (Lorg/w3c/dom/Element;Lunearth/levels/Level;)V
05-06 16:12:32.875: W/dalvikvm(17509): Verifier rejected class Lunearth/levels/LevelReader;
05-06 16:12:32.890: W/dalvikvm(17509): threadid=11: thread exiting with uncaught exception (group=0x40c331f8)
05-06 16:12:32.895: E/AndroidRuntime(17509): FATAL EXCEPTION: GLThread 1062
05-06 16:12:32.895: E/AndroidRuntime(17509): java.lang.VerifyError: unearth/levels/LevelReader
05-06 16:12:32.895: E/AndroidRuntime(17509):    at unearth.Game.startGame(Game.java:201)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at unearth.Game.update(Game.java:713)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at unearth.screens.LoadScreen.update(LoadScreen.java:56)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at unearth.UnearthListener.render(UnearthListener.java:71)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:423)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1462)
05-06 16:12:32.895: E/AndroidRuntime(17509):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1216)
05-06 16:12:58.600: D/dalvikvm(17509): GC_CONCURRENT freed 334K, 3% free 16196K/16647K, paused 2ms+6ms

Update:

Maybe this project has some useful code? http://code.google.com/p/android-scripting/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:24:37+00:00Added an answer on June 3, 2026 at 2:24 pm

    I found a way of using LuaJ on Android! 🙂

    The key is to use the LuaJ API directly as opposed to through javax.script. It’s a little tricky to figure out as there’s no tutorials, so here’s a before and after so that others don’t have to go through picking through the LuaJ source code and JavaDoc. I really hope this helps someone as it drove me bonkers!

    Note: “secretgame” isn’t the actual name of my game 😉

    After:

    package secretgame.scripting;
    
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    
    import org.luaj.vm2.LuaClosure;
    import org.luaj.vm2.LuaTable;
    import org.luaj.vm2.LuaValue;
    import org.luaj.vm2.Prototype;
    import org.luaj.vm2.compiler.LuaC;
    import org.luaj.vm2.lib.jse.CoerceJavaToLua;
    import org.luaj.vm2.lib.jse.JsePlatform;
    
    import secretgame.SecretGameException;
    import secretgame.events.EventArgs;
    import secretgame.levels.Level;
    
    public class DirectLuaj implements Lua
    {
      private final Level level;
      private final ScriptTools scriptTools;
      private final ScriptEvents scriptEvents;
      private int nextId = 0;
      private ArrayList<LuaClosure> scripts = new ArrayList<LuaClosure>();
    
      public DirectLuaj(Level level, ScriptTools scriptTools,
          ScriptEvents scriptEvents)
      {
        this.level = level;
        this.scriptTools = scriptTools;
        this.scriptEvents = scriptEvents;
      }
    
      @Override
      public int add(String scriptText) throws SecretGameException
      {
        try {
          InputStream input = new ByteArrayInputStream(scriptText.getBytes());
          Prototype p = LuaC.compile(input, "script");
          LuaValue g = JsePlatform.standardGlobals();
          LuaClosure c = new LuaClosure(p, g);
          scripts.add(c);
        }
        catch (IOException e) {
          throw new SecretGameException("compile failed", e);
        }
    
        return nextId++;
      }
    
      @Override
      public void run(int id, EventArgs args) throws SecretGameException
      {
        LuaClosure script = scripts.get(id);
    
        LuaTable bindings = new LuaTable();
    
        bindings.set("java", toLua(scriptTools));
        bindings.set("level", toLua(level));
        bindings.set("args", toLua(args));
        bindings.set("events", toLua(scriptEvents));
    
        script.setfenv(bindings);
    
        script.call();
      }
    
      private LuaValue toLua(Object javaValue) {
        return javaValue == null? LuaValue.NIL:
                javaValue instanceof LuaValue? (LuaValue) javaValue:
                CoerceJavaToLua.coerce(javaValue);
      }
    }
    

    Before:

    package secretgame.scripting;
    
    import java.util.ArrayList;
    
    import javax.script.Bindings;
    import javax.script.Compilable;
    import javax.script.CompiledScript;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    import javax.script.ScriptException;
    
    import secretgame.SecretGameException;
    import secretgame.events.EventArgs;
    import secretgame.levels.Level;
    
    // sadly this won't work on Android because there's no such thing
    // as javax.script in Dalvik ... dumb Android java :|
    public class JavaxScriptingLua implements Lua
    {
      private ScriptEngine scriptEngine;
      private final Level level;
      private final ScriptTools scriptTools;
      private final ScriptEvents scriptEvents;
      private int nextId = 0;
      private ArrayList<CompiledScript> scripts = new ArrayList<CompiledScript>();
    
      public JavaxScriptingLua(Level level, ScriptTools scriptTools, ScriptEvents scriptEvents)
      {
        this.level = level;
        this.scriptTools = scriptTools;
        this.scriptEvents = scriptEvents;
    
        ScriptEngineManager sem = new ScriptEngineManager();
        scriptEngine = sem.getEngineByExtension(".lua");
      }
    
      public int add(String scriptText) throws SecretGameException
      {
        try {
          CompiledScript script = ((Compilable)scriptEngine).compile(scriptText);
          scripts.add(script);
        }
        catch (ScriptException e) {
          throw new SecretGameException("could not compile lua.", e);
        }
    
        return nextId++;
      }
    
      public void run(int id, EventArgs args) throws SecretGameException
      {    
        Bindings bindings = scriptEngine.createBindings();
    
        bindings.put("java", scriptTools);
        bindings.put("level", level);
        bindings.put("args", args);
        bindings.put("events", scriptEvents);
    
        try {
          scripts.get(id).eval(bindings);
        }
        catch (ScriptException e) {
          throw new SecretGameException("could not run script.", e);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.