Simplify layout of lua test script locations.

This commit is contained in:
James Roseborough
2012-09-07 14:05:41 +00:00
parent 3bacea878e
commit f2d1106fe5
27 changed files with 151 additions and 166 deletions

View File

@@ -715,4 +715,31 @@ public class LuaTable extends LuaValue {
LuaValue valmt = val.getmetatable();
return valmt!=null && LuaValue.eqmtcall(this, m_metatable, val, valmt);
}
/** Unpack all the elements of this table */
public Varargs unpack() {
return unpack(1, this.length());
}
/** Unpack all the elements of this table from element i */
public Varargs unpack(int i) {
return unpack(i, this.length());
}
/** Unpack the elements from i to j inclusive */
public Varargs unpack(int i, int j) {
int n = j + 1 - i;
switch (n) {
case 0: return NONE;
case 1: return get(i);
case 2: return varargsOf(get(i), get(i+1));
default:
if (n < 0)
return NONE;
LuaValue[] v = new LuaValue[n];
while (--n >= 0)
v[n] = get(i+n);
return varargsOf(v);
}
}
}

View File

@@ -119,19 +119,12 @@ public class TableLib extends OneArgFunction {
}
case 6: // "unpack", // (list [,i [,j]]) -> result1, ...
{
int na = args.narg();
LuaTable t = args.checktable(1);
int n = t.length();
int i = na>=2? args.checkint(2): 1;
int j = na>=3? args.checkint(3): n;
n = j-i+1;
if ( n<0 ) return NONE;
if ( n==1 ) return t.get(i);
if ( n==2 ) return varargsOf(t.get(i),t.get(j));
LuaValue[] v = new LuaValue[n];
for ( int k=0; k<n; k++ )
v[k] = t.get(i+k);
return varargsOf(v);
switch (args.narg()) {
case 1: return t.unpack();
case 2: return t.unpack(args.checkint(2));
default: return t.unpack(args.checkint(2), args.checkint(3));
}
}
}
return NONE;

View File

@@ -205,6 +205,7 @@ public class lua {
} else {
System.out.println( "Not a LuaClosure: "+c);
}
Print.print(((LuaClosure)c).p);
} finally {
script.close();
}
@@ -219,8 +220,7 @@ public class lua {
LuaTable arg = LuaValue.tableOf();
for ( int j=0; j<args.length; j++ )
arg.set( j-i, LuaValue.valueOf(args[j]) );
_G.set( "arg", arg );
return _G.get("unpack").invoke(arg);
return arg.unpack();
}
private static void interactiveMode( ) throws IOException {

View File

@@ -56,7 +56,7 @@ import org.luaj.vm2.lib.VarArgFunction;
* _G.load(new BaseLib());
* _G.load(new PackageLib());
* _G.load(new LuajavaLib());
* _G.get("loadstring").call( LuaValue.valueOf(
* _G.get("load").call( LuaValue.valueOf(
* "sys = luajava.bindClass('java.lang.System')\n"+
* "print ( sys:currentTimeMillis() )\n" ) ).call();
* } </pre>