1
votes

I use LuaJ, it contains a library: luajava which allows to pass a class via Reflection to lua enviroment. Do you know how to do this?? I noticed that there is a way to pass compiled class:

_G.get("load").call(LuaValue.valueOf(
            "sys = luajava.bindClass('java.lang.System')\n" +
                    "print ( sys:currentTimeMillis() )\n")).call(); 

What about not compiled class: *.java? how to pass it?

1

1 Answers

0
votes

If you need to call class via Reflection , you can do this without additional third party lib e.g.

        //calling class via reflection
        Class cls = Class.forName("com.test.reflection.AppTest");
        Object obj = cls.newInstance();

        //call the printIt method
        Method method = cls.getDeclaredMethod("printIt", noparams);
        method.invoke(obj, null);

        //call the printItString method, pass a String param 
        method = cls.getDeclaredMethod("printItString", paramString);
        method.invoke(obj, new String("mkyong"));

        //call the printCounter method
        method = cls.getDeclaredMethod("printCounter", noparams);
        method.invoke(obj, null);