Luajavalib #75

Closed
opened 2020-08-13 18:31:20 +00:00 by Nogitsu · 4 comments
Nogitsu commented 2020-08-13 18:31:20 +00:00 (Migrated from github.com)

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..

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..
jplwill commented 2020-08-13 18:37:31 +00:00 (Migrated from github.com)

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.)

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.)
Nogitsu commented 2020-08-13 18:43:36 +00:00 (Migrated from github.com)

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

I started looking at it in the same period, I looked at it but it's not worth a wiki or documentation..
zhuxl13817468272 commented 2021-12-30 11:48:09 +00:00 (Migrated from github.com)

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

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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#75