luaj
luaj copied to clipboard
Luajavalib
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..
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.)
I started looking at it in the same period, I looked at it but it's not worth a wiki or documentation..
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