2

I want to run a Lua script from Java GUI. Can I develop it in a Java IDE. What I want to achieve:

  1. I will have a button in Java that will run a Lua script.
  2. Then the Lua script will run and return something that I can capture in my Java code and show it in the GUI of java.

1 Answer 1

3

I found a package, which helps in integration of Lua with Java.

Simple Application:

import org.luaj.vm2.*;
import org.luaj.vm2.lib.jse.*;

Globals globals = JsePlatform.standardGlobals();
LuaValue chunk = globals.loadfile("examples/lua/hello.lua");
chunk.call();

On doing chuck.call(), save the return value to a variable. See, if that helps.

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

4 Comments

when is inside the chunk.call() thought it is returning me the line string "hello world" ??
Sorry, I didn't understood what you're saying.
can i run any linux terminal command using this and get the result?? like 'ls' using luaj
@setubasak I am not sure about that, coz loadfile basically load lua file and is been executed by doing call().

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.