luaj icon indicating copy to clipboard operation
luaj copied to clipboard

Luajavalib

Open Nogitsu opened this issue 4 years ago • 3 comments

I can't find any references or help for the Luajavalib, I only have the things from http://luaj.org/luaj/3.0/api/index.html but that's not helping me a lot..

Nogitsu avatar Aug 13 '20 18:08 Nogitsu

See the swing example at https://github.com/luaj/luaj/blob/master/examples/lua/swingapp.lua, and the docs for CoerceJavaToLua.coerce(). I'm not seeing anything else. (Not an expert, me, started looking at LuaJ last week.)

jplwill avatar Aug 13 '20 18:08 jplwill

I started looking at it in the same period, I looked at it but it's not worth a wiki or documentation..

Nogitsu avatar Aug 13 '20 18:08 Nogitsu

In Java, my solution to this problem is override JsePlatform and LuajavaLib

public class JsePlatformFix extends JsePlatform{

public static Globals standardGlobals() {
    Globals globals = new Globals();
    globals.load(new JseBaseLib());
    globals.load(new PackageLib());
    globals.load(new Bit32Lib());
    globals.load(new TableLib());
    globals.load(new StringLib());
    globals.load(new CoroutineLib());
    globals.load(new JseMathLib());
    globals.load(new JseIoLib());
    globals.load(new JseOsLib());
    globals.load(new LuajavaLibFix());
    LoadState.install(globals);
    LuaC.install(globals);
    return globals;
}

public class LuajavaLibFix extends LuajavaLib {

public LuajavaLibFix() {}

// load classes using app loader to allow luaj to be used as an extension
@Override
protected Class classForName(String name) throws ClassNotFoundException {
    return Class.forName(name, true, Thread.currentThread().getContextClassLoader());
}

}

Globals globals = JsePlatformFix.standardGlobals(); LuaValue load = globals.load(luaScript); LuaValue call = load.call();

In LuaScript, use like that : local instance = luajava.newInstance('com.xxx.xxx')

In practice, it can execute successful. Wish can help you

zhuxl13817468272 avatar Dec 30 '21 11:12 zhuxl13817468272