1

So I’m learning java right now and built a GUI which functions how I want. But I need a way I can call a lua script within my java script. I’m pretty good with lua and have used the code below in lua to launch another lua script externally through the cmd.

os.execute(‘start “Data save” cmd /k “cd ‘ .. path .. ‘ & ‘ .. r_path .. ‘bin\luae.exe testscript.lua & exit “‘)

Me being new to java was researching and was getting really confused. But the reason behind this is I’m making an external dialog for a game that only reads lua code. So the plan is to get the information from the dialog and execute the lua file with the new dialog info then generate a new lua file with this information with :write() in lua.

I just need to be able to execute a lua file within java with arguments that’s it.

5
  • 1
    java...or javascript??? Commented Jul 20, 2018 at 4:28
  • I think just java. Commented Jul 20, 2018 at 4:35
  • 1
    you should know what language you're using. Otherwise how can we help you? Commented Jul 20, 2018 at 4:50
  • 1
    Possibly relevant: github.com/darmie/LuaJ Commented Jul 20, 2018 at 4:50
  • Im using Java and I looked into LuaJ but confused on where to install it. Commented Jul 20, 2018 at 18:38

1 Answer 1

1

I don't know if this is the answer you're looking for, but you can run shell commands in Java with the Runtime class which is already included in the java.lang package, and its exec(String cmd) method is generally a good os.execute substitute in java itself.

Usage

public class Test {
    public static void main(String[] args) {
        Runtime.getRuntime().exec('start "Data save" cmd /k "cd ' .. path .. ' & ' .. r_path .. 'bin\luae.exe testscript.lua & exit "')
    }
}

You might want to look more into the Runtime class in general.

But if you're literally looking to interpret Lua in Java then I heard LuaJ is a good option.

Sign up to request clarification or add additional context in comments.

Comments

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.