Let sample applet use a plain class loader within the luajava library.
This commit is contained in:
@@ -4,10 +4,21 @@ import java.io.InputStream;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.luaj.vm2.Globals;
|
import org.luaj.vm2.Globals;
|
||||||
|
import org.luaj.vm2.LoadState;
|
||||||
import org.luaj.vm2.LuaValue;
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.luaj.vm2.compiler.LuaC;
|
||||||
|
import org.luaj.vm2.lib.Bit32Lib;
|
||||||
|
import org.luaj.vm2.lib.CoroutineLib;
|
||||||
|
import org.luaj.vm2.lib.PackageLib;
|
||||||
import org.luaj.vm2.lib.ResourceFinder;
|
import org.luaj.vm2.lib.ResourceFinder;
|
||||||
|
import org.luaj.vm2.lib.StringLib;
|
||||||
|
import org.luaj.vm2.lib.TableLib;
|
||||||
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
import org.luaj.vm2.lib.jse.CoerceJavaToLua;
|
||||||
import org.luaj.vm2.lib.jse.JsePlatform;
|
import org.luaj.vm2.lib.jse.JseBaseLib;
|
||||||
|
import org.luaj.vm2.lib.jse.JseIoLib;
|
||||||
|
import org.luaj.vm2.lib.jse.JseMathLib;
|
||||||
|
import org.luaj.vm2.lib.jse.JseOsLib;
|
||||||
|
import org.luaj.vm2.lib.jse.LuajavaLib;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Applet that forwards Applet lifecycle events to a lua script.
|
* Simple Applet that forwards Applet lifecycle events to a lua script.
|
||||||
@@ -59,8 +70,20 @@ public class SampleApplet extends Applet implements ResourceFinder {
|
|||||||
script = default_script;
|
script = default_script;
|
||||||
System.out.println("Loading " + script);
|
System.out.println("Loading " + script);
|
||||||
|
|
||||||
// Construct globals to use.
|
// Construct globals specific to the applet platform.
|
||||||
globals = JsePlatform.standardGlobals();
|
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 AppletLuajavaLib());
|
||||||
|
LoadState.install(globals);
|
||||||
|
LuaC.install(globals);
|
||||||
|
|
||||||
// Use custom resource finder.
|
// Use custom resource finder.
|
||||||
globals.FINDER = this;
|
globals.FINDER = this;
|
||||||
@@ -127,4 +150,13 @@ public class SampleApplet extends Applet implements ResourceFinder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class AppletLuajavaLib extends LuajavaLib {
|
||||||
|
public AppletLuajavaLib() {}
|
||||||
|
protected Class classForName(String name) throws ClassNotFoundException {
|
||||||
|
// Use plain class loader in applets.
|
||||||
|
return Class.forName(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class LuajavaLib extends VarArgFunction {
|
|||||||
// LuaValue modname = args.arg1();
|
// LuaValue modname = args.arg1();
|
||||||
LuaValue env = args.arg(2);
|
LuaValue env = args.arg(2);
|
||||||
LuaTable t = new LuaTable();
|
LuaTable t = new LuaTable();
|
||||||
bind( t, LuajavaLib.class, NAMES, BINDCLASS );
|
bind( t, this.getClass(), NAMES, BINDCLASS );
|
||||||
env.set("luajava", t);
|
env.set("luajava", t);
|
||||||
env.get("package").get("loaded").set("luajava", t);
|
env.get("package").get("loaded").set("luajava", t);
|
||||||
return t;
|
return t;
|
||||||
|
|||||||
Reference in New Issue
Block a user