Fix imports, length coercion, script sample

This commit is contained in:
James Roseborough
2011-03-03 18:27:21 +00:00
parent a88789517d
commit 90839804ef
3 changed files with 4 additions and 16 deletions

View File

@@ -116,7 +116,7 @@ public class ScriptEngineSample {
CompiledScript cs = ((Compilable)e).compile( CompiledScript cs = ((Compilable)e).compile(
"test = test or luajava.newInstance(\"java.lang.String\", \"test\")\n" + "test = test or luajava.newInstance(\"java.lang.String\", \"test\")\n" +
"print( 'test', type(test), test, tostring(test) )\n" + "print( 'test', type(test), test, tostring(test) )\n" +
"return test:toString()"); "return tostring(test)");
Bindings b = e.createBindings(); Bindings b = e.createBindings();
Object resultstring = cs.eval(b); Object resultstring = cs.eval(b);
b.put("test", new SomeUserClass()); b.put("test", new SomeUserClass());

View File

@@ -41,7 +41,7 @@ public class JavaArray extends LuaUserdata {
public LuaValue get(LuaValue key) { public LuaValue get(LuaValue key) {
if ( key.equals(LENGTH) ) if ( key.equals(LENGTH) )
return CoerceJavaToLua.coerce(Array.getLength(m_instance)); return valueOf(Array.getLength(m_instance));
if ( key.isint() ) { if ( key.isint() ) {
int i = key.toint() - 1; int i = key.toint() - 1;
return i>=0 && i<Array.getLength(m_instance)? return i>=0 && i<Array.getLength(m_instance)?

View File

@@ -27,8 +27,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy; import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
import org.luaj.vm2.LuaError; import org.luaj.vm2.LuaError;
import org.luaj.vm2.LuaTable; import org.luaj.vm2.LuaTable;
@@ -38,7 +36,6 @@ import org.luaj.vm2.compiler.LuaC;
import org.luaj.vm2.lib.LibFunction; import org.luaj.vm2.lib.LibFunction;
import org.luaj.vm2.lib.PackageLib; import org.luaj.vm2.lib.PackageLib;
import org.luaj.vm2.lib.VarArgFunction; import org.luaj.vm2.lib.VarArgFunction;
import org.luaj.vm2.lib.jme.JmePlatform;
/** /**
* Subclass of {@link LibFunction} which implements the features of the luajava package. * Subclass of {@link LibFunction} which implements the features of the luajava package.
@@ -70,8 +67,8 @@ import org.luaj.vm2.lib.jme.JmePlatform;
* <p> * <p>
* This has been implemented to match as closely as possible the behavior in the corresponding library in C. * This has been implemented to match as closely as possible the behavior in the corresponding library in C.
* @see LibFunction * @see LibFunction
* @see JsePlatform * @see org.luaj.vm2.lib.jse.JsePlatform
* @see JmePlatform * @see org.luaj.vm2.lib.jme.JmePlatform
* @see LuaC * @see LuaC
* @see <a href="http://www.keplerproject.org/luajava/manual.html#luareference">http://www.keplerproject.org/luajava/manual.html#luareference</a> * @see <a href="http://www.keplerproject.org/luajava/manual.html#luareference">http://www.keplerproject.org/luajava/manual.html#luareference</a>
*/ */
@@ -92,17 +89,8 @@ public class LuajavaLib extends VarArgFunction {
"loadLib", "loadLib",
}; };
static final Map classMetatables = new HashMap();
static final int METHOD_MODIFIERS_VARARGS = 0x80; static final int METHOD_MODIFIERS_VARARGS = 0x80;
static final LuaValue LENGTH = valueOf("length");
static final Map consCache = new HashMap();
static final Map consIndex = new HashMap();
static final Map methCache = new HashMap();
static final Map methIndex = new HashMap();
public LuajavaLib() { public LuajavaLib() {
} }