0

Here is ex how to call new instance of java obj, but how to import mylib.jar is not explained

For ex. I have mylib.jar and there is class com.example.MyClass.

    public class MyClass{
    public String getHelloPersonName(String name){
          return "Hello, " + name;
    }

I want to create the java class instance and call this method

How to import the .jar file to the lua code, and create an instance of MyClass and call method from it?

function init()

end
Egor Skriptunoff
  • 906
  • 1
  • 8
  • 23
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
  • I'm not sure about importing the file into Lua, but maybe you can do something with [os.execute](http://lua-users.org/wiki/OsLibraryTutorial), and call `java -jar mylib.jar` with arguments? – Mark Oct 22 '18 at 08:37
  • @Mark Here is ex how to call new instance of java obj https://stackoverflow.com/a/35392230/2425851, but how to import `mylib.jar` is not explained – NickUnuchek Oct 22 '18 at 09:04
  • Create `program.lua` assuming your lib is already loaded in Java. Then run `java -cp "lib/luaj-jse-3.0.1.jar;/path/to/mylib.jar" lua program.lua` – Egor Skriptunoff Oct 22 '18 at 09:26
  • @EgorSkriptunoff nothing happens after run of the command – NickUnuchek Oct 22 '18 at 09:48
  • @NickUnuchek - Please show your `program.lua` – Egor Skriptunoff Oct 22 '18 at 12:25
  • @EgorSkriptunoff `function init() end`. Egor please explain fully , because I'm new in lua. I'm android dev. – NickUnuchek Oct 22 '18 at 12:52
  • 1
    The link you posted shows an example how to create instance of Java class by using `luajava.newInstance()`. Try it inside your `program.lua`. Read LuaJ API about other operations (passing and returning values and so on). – Egor Skriptunoff Oct 22 '18 at 13:38

0 Answers0