Improve jsr-223 bindings, allow ".lua" or "lua" as extensions, find classes when added as vm extension, enhance javadoc, add sources jar.
This commit is contained in:
@@ -155,7 +155,7 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
|
||||
return c.getResourceAsStream(filename.startsWith("/")? filename: "/"+filename);
|
||||
}
|
||||
|
||||
public static final class BaseLib2 extends TwoArgFunction {
|
||||
static final class BaseLib2 extends TwoArgFunction {
|
||||
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||
switch ( opcode ) {
|
||||
case 0: // "collectgarbage", // ( opt [,arg] ) -> value
|
||||
@@ -202,7 +202,7 @@ public class BaseLib extends OneArgFunction implements ResourceFinder {
|
||||
return f;
|
||||
}
|
||||
|
||||
public static final class BaseLibV extends VarArgFunction {
|
||||
static final class BaseLibV extends VarArgFunction {
|
||||
public BaseLib baselib;
|
||||
public Varargs invoke(Varargs args) {
|
||||
switch ( opcode ) {
|
||||
|
||||
@@ -247,7 +247,7 @@ public class IoLib extends OneArgFunction {
|
||||
((IoLibV) t.get(k[i])).iolib = this;
|
||||
}
|
||||
|
||||
public static final class IoLibV extends VarArgFunction {
|
||||
static final class IoLibV extends VarArgFunction {
|
||||
public IoLib iolib;
|
||||
public IoLibV() {
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class MathLib extends OneArgFunction {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static final class MathLib1 extends OneArgFunction {
|
||||
static final class MathLib1 extends OneArgFunction {
|
||||
public LuaValue call(LuaValue arg) {
|
||||
switch ( opcode ) {
|
||||
case 0: return valueOf(Math.abs(arg.checkdouble()));
|
||||
@@ -122,7 +122,7 @@ public class MathLib extends OneArgFunction {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class MathLib2 extends TwoArgFunction {
|
||||
static final class MathLib2 extends TwoArgFunction {
|
||||
protected MathLib mathlib;
|
||||
public LuaValue call(LuaValue arg1, LuaValue arg2) {
|
||||
switch ( opcode ) {
|
||||
@@ -189,7 +189,7 @@ public class MathLib extends OneArgFunction {
|
||||
return p;
|
||||
}
|
||||
|
||||
public static final class MathLibV extends VarArgFunction {
|
||||
static final class MathLibV extends VarArgFunction {
|
||||
protected MathLib mathlib;
|
||||
public Varargs invoke(Varargs args) {
|
||||
switch ( opcode ) {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class PackageLib extends OneArgFunction {
|
||||
return env;
|
||||
}
|
||||
|
||||
public static final class PkgLib1 extends OneArgFunction {
|
||||
static final class PkgLib1 extends OneArgFunction {
|
||||
PackageLib lib;
|
||||
public PkgLib1(LuaValue env,String name, int opcode, PackageLib lib) {
|
||||
this.env = env;
|
||||
@@ -151,7 +151,7 @@ public class PackageLib extends OneArgFunction {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PkgLibV extends VarArgFunction {
|
||||
static final class PkgLibV extends VarArgFunction {
|
||||
PackageLib lib;
|
||||
public PkgLibV(LuaValue env,String name, int opcode, PackageLib lib) {
|
||||
this.env = env;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class StringLib extends OneArgFunction {
|
||||
return t;
|
||||
}
|
||||
|
||||
public static final class StringLib1 extends OneArgFunction {
|
||||
static final class StringLib1 extends OneArgFunction {
|
||||
public LuaValue call(LuaValue arg) {
|
||||
switch ( opcode ) {
|
||||
case 0: return dump(arg); // dump (function)
|
||||
@@ -95,7 +95,7 @@ public class StringLib extends OneArgFunction {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class StringLibV extends VarArgFunction {
|
||||
static final class StringLibV extends VarArgFunction {
|
||||
public Varargs invoke(Varargs args) {
|
||||
switch ( opcode ) {
|
||||
case 0: return StringLib.byte_( args );
|
||||
@@ -319,7 +319,7 @@ public class StringLib extends OneArgFunction {
|
||||
|
||||
private static final String FLAGS = "-+ #0";
|
||||
|
||||
private static class FormatDesc {
|
||||
static class FormatDesc {
|
||||
|
||||
private boolean leftAdjust;
|
||||
private boolean zeroPad;
|
||||
@@ -810,7 +810,7 @@ public class StringLib extends OneArgFunction {
|
||||
CHAR_TABLE['\f'] |= MASK_SPACE;
|
||||
};
|
||||
|
||||
private static class MatchState {
|
||||
static class MatchState {
|
||||
final LuaString s;
|
||||
final LuaString p;
|
||||
final Varargs args;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TableLib extends OneArgFunction {
|
||||
return NIL;
|
||||
}
|
||||
|
||||
public static final class TableLibV extends VarArgFunction {
|
||||
static final class TableLibV extends VarArgFunction {
|
||||
public Varargs invoke(Varargs args) {
|
||||
switch ( opcode ) {
|
||||
case 0: { // "remove" (table [, pos]) -> removed-ele
|
||||
|
||||
@@ -123,14 +123,14 @@ public class LuajavaLib extends VarArgFunction {
|
||||
return t;
|
||||
}
|
||||
case BINDCLASS: {
|
||||
final Class clazz = Class.forName(args.checkjstring(1));
|
||||
final Class clazz = classForName(args.checkjstring(1));
|
||||
return toUserdata( clazz, clazz );
|
||||
}
|
||||
case NEWINSTANCE:
|
||||
case NEW: {
|
||||
// get constructor
|
||||
final LuaValue c = args.checkvalue(1);
|
||||
final Class clazz = (opcode==NEWINSTANCE? Class.forName(c.tojstring()): (Class) c.checkuserdata(Class.class));
|
||||
final Class clazz = (opcode==NEWINSTANCE? classForName(c.tojstring()): (Class) c.checkuserdata(Class.class));
|
||||
final Varargs consargs = args.subargs(2);
|
||||
final long paramssig = LuajavaLib.paramsSignatureOf( consargs );
|
||||
final Constructor con = resolveConstructor( clazz, paramssig );
|
||||
@@ -153,7 +153,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
// get the interfaces
|
||||
final Class[] ifaces = new Class[niface];
|
||||
for ( int i=0; i<niface; i++ )
|
||||
ifaces[i] = Class.forName(args.checkjstring(i+1));
|
||||
ifaces[i] = classForName(args.checkjstring(i+1));
|
||||
|
||||
// create the invocation handler
|
||||
InvocationHandler handler = new InvocationHandler() {
|
||||
@@ -193,7 +193,7 @@ public class LuajavaLib extends VarArgFunction {
|
||||
// get constructor
|
||||
String classname = args.checkjstring(1);
|
||||
String methodname = args.checkjstring(2);
|
||||
Class clazz = Class.forName(classname);
|
||||
Class clazz = classForName(classname);
|
||||
Method method = clazz.getMethod(methodname, new Class[] {});
|
||||
Object result = method.invoke(clazz, new Object[] {});
|
||||
if ( result instanceof LuaValue ) {
|
||||
@@ -214,6 +214,11 @@ public class LuajavaLib extends VarArgFunction {
|
||||
}
|
||||
}
|
||||
|
||||
// load classes using app loader to allow luaj to be used as an extension
|
||||
protected Class classForName(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name, true, ClassLoader.getSystemClassLoader());
|
||||
}
|
||||
|
||||
// params signature is
|
||||
// - low 6-bits are number of parameters
|
||||
// - each of next 9 6-bit fields encode a parameter type:
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
package org.luaj.vm2.script;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
@@ -33,7 +32,10 @@ import javax.script.ScriptEngineFactory;
|
||||
*/
|
||||
public class LuaScriptEngineFactory implements ScriptEngineFactory {
|
||||
|
||||
private static final String FILEEXT = ".lua";
|
||||
private static final String [] EXTENSIONS = {
|
||||
"lua",
|
||||
".lua",
|
||||
};
|
||||
|
||||
private static final String [] MIMETYPES = {
|
||||
"text/plain",
|
||||
@@ -54,7 +56,7 @@ public class LuaScriptEngineFactory implements ScriptEngineFactory {
|
||||
|
||||
|
||||
public LuaScriptEngineFactory() {
|
||||
extensions = Collections.nCopies(1, FILEEXT);
|
||||
extensions = Arrays.asList(EXTENSIONS);
|
||||
mimeTypes = Arrays.asList(MIMETYPES);
|
||||
names = Arrays.asList(NAMES);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user