0

I'm writing a 2D game in Java and have reached the point where I believe I'm much better off keeping the logic separate from my current game in the form of scripts, as I plan to reuse this engine for another game after I'm done with this current game. I've found the syntax and capabilities of lua to be inviting. However, I've had a hell of a time getting this to work. I got LuaJava installed and the library works in Eclipse. But when I run my hello.lua it doesn't print to the console at all. It leaves no trace of even running the script, in fact. I'm discouraged as I'd really like to get to scripting and working on my game more, but I've just had so much trouble. If no one that sees this is familiar with luajava, luaj, kahlua, etc. please refer me to a better/EASIER scripting language to implement. I know Jython and Rhino are more popular, but both seem just as complicated to implement/use.

Test.java

import org.keplerproject.luajava.LuaState;
import org.keplerproject.luajava.LuaStateFactory;

public class Test 
{
    public static void main(String[] args)
    {
        LuaState lua = LuaStateFactory.newLuaState();

        lua.openLibs();

        lua.LdoFile("hello.lua");

        lua.close();
    }
}

hello.lua

 print("Hello from lua!")

1 Answer 1

0

How you executing the script? If you are executing the script from your Java program by clicking on the .jar file then it won't open a console. You must open cmd prompt and execute the Java program from there using the following cmd

java -jar jarFileName.jar
Sign up to request clarification or add additional context in comments.

4 Comments

I'm trying to execute the script from within the application at runtime. It's a 2D game where I'm planning to run scripts when certain actions are performed.
The script will execute with no problem. You just won't see any output to the console unless the program is excited from the console (Java will not open a console to display an output).
I'm talking about the console when I'm running the program in Eclipse. Kia should be printing to it.
Oh ok sorry I am not sure about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.