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>

View File

@@ -23,11 +23,11 @@ abstract public class AbstractUnitTests extends TestCase {
private final String jar;
private LuaTable _G;
public AbstractUnitTests(String zipfile, String dir) {
public AbstractUnitTests(String zipdir, String zipfile, String dir) {
URL zip = null;
zip = getClass().getResource(zipfile);
if ( zip == null ) {
File file = new File("test/junit/org/luaj/vm2/compiler/"+zipfile);
File file = new File(zipdir+"/"+zipfile);
try {
if ( file.exists() )
zip = file.toURI().toURL();
@@ -71,7 +71,7 @@ abstract public class AbstractUnitTests extends TestCase {
String actual = protoToString(p);
// load expected value from jar
byte[] luac = bytesFromJar(path + "c");
byte[] luac = bytesFromJar(path.substring(0, path.length()-4)+".lc");
Prototype e = loadFromBytes(luac, file);
String expected = protoToString(e);

View File

@@ -5,7 +5,7 @@ package org.luaj.vm2.compiler;
public class CompilerUnitTests extends AbstractUnitTests {
public CompilerUnitTests() {
super("lua5.2.1-tests.zip", "lua5.2.1-tests");
super("test/lua", "luaj3.0-tests.zip", "lua5.2.1-tests");
}
public void testAll() { doTest("all.lua"); }

View File

@@ -17,8 +17,7 @@ package org.luaj.vm2.compiler;
public class RegressionTests extends AbstractUnitTests {
public RegressionTests() {
super( "regressions.zip",
"regressions" );
super( "test/lua", "luaj3.0-tests.zip", "regressions" );
}
public void testModulo() { doTest("modulo.lua"); }

View File

@@ -196,7 +196,7 @@ public class LuaJavaCoercionTest extends TestCase {
public void testExceptionMessage() {
String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
"return pcall( c.someMethod, c )";
Varargs vresult = _G.get("loadstring").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
Varargs vresult = _G.get("load").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
LuaValue status = vresult.arg1();
LuaValue message = vresult.arg(2);
assertEquals( LuaValue.FALSE, status );
@@ -206,7 +206,7 @@ public class LuaJavaCoercionTest extends TestCase {
public void testLuaErrorCause() {
String script = "luajava.bindClass( \""+SomeClass.class.getName()+"\"):someMethod()";
LuaValue chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
LuaValue chunk = _G.get("load").call(LuaValue.valueOf(script));
try {
chunk.invoke(LuaValue.NONE);
fail( "call should not have succeeded" );
@@ -235,7 +235,7 @@ public class LuaJavaCoercionTest extends TestCase {
" ) or '-nil')\n" +
" end,\n" +
"} )\n";
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
if ( ! chunk.arg1().toboolean() )
fail( chunk.arg(2).toString() );
LuaValue result = chunk.arg1().call();
@@ -260,7 +260,7 @@ public class LuaJavaCoercionTest extends TestCase {
//"print(bigNumB:toString())\n" +
//"print(bigNumC:toString())\n" +
"return bigNumA:toString(), bigNumB:toString(), bigNumC:toString()";
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
if ( ! chunk.arg1().toboolean() )
fail( chunk.arg(2).toString() );
Varargs results = chunk.arg1().invoke();
@@ -345,7 +345,7 @@ public class LuaJavaCoercionTest extends TestCase {
"local b = a:set(a:get"+typename+"())\n" +
"local c = a:setr(a:get"+typename+"())\n" +
"return b,c";
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
if ( ! chunk.arg1().toboolean() )
fail( chunk.arg(2).toString() );
Varargs results = chunk.arg1().invoke();

View File

@@ -59,11 +59,11 @@ c,e = load(f)
if c then print('load: ', pcall(c)) else print('load failed:', e) end
-- loadfile
-- loadstring
-- load
local lst = "print(3+4); return 8"
local chunk, err = loadstring( lst )
print( 'loadstring("'..lst..'")', chunk, err )
print( 'loadstring("'..lst..'")()', chunk() )
local chunk, err = load( lst )
print( 'load("'..lst..'")', chunk, err )
print( 'load("'..lst..'")()', chunk() )
-- pairs
print( 'pcall(pairs)', pcall(pairs) )
@@ -98,7 +98,6 @@ print( 'la()', la() )
function ga() return pcall(type) end
print( 'ga()', ga() )
-- getfenv, setfenv: tested in setfenv.lua
-- getmetatable, setmetatable
ta = { aa1="aaa1", aa2="aaa2" }
tb = { bb1="bbb1", bb2="bbb2" }
@@ -255,51 +254,6 @@ print( 'tostring(tostring)', type(tostring(tostring)) )
print( 'tostring(function() end)', type(tostring(function() end)) )
print( 'tostring({"one","two",a="aa",b="bb"})', type(tostring({"one","two",a="aa",b="bb"})) )
-- unpack
print( 'pcall(unpack)', pcall(unpack) );
print( 'pcall(unpack,nil)', pcall(unpack,nil) );
print( 'pcall(unpack,"abc")', pcall(unpack,"abc") );
print( 'pcall(unpack,1)', pcall(unpack,1) );
print( 'unpack({"aa"})', unpack({"aa"}) );
print( 'unpack({"aa","bb"})', unpack({"aa","bb"}) );
print( 'unpack({"aa","bb","cc"})', unpack({"aa","bb","cc"}) );
local t = {"aa","bb","cc","dd","ee","ff"}
print( 'pcall(unpack,t)', pcall(unpack,t) );
print( 'pcall(unpack,t,2)', pcall(unpack,t,2) );
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
print( 'pcall(unpack,t,1)', pcall(unpack,t,1) );
print( 'pcall(unpack,t,1,5)', pcall(unpack,t,1,5) );
print( 'pcall(unpack,t,1,6)', pcall(unpack,t,1,6) );
print( 'pcall(unpack,t,1,7)', pcall(unpack,t,1,7) );
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
print( 'pcall(unpack,t,0,5)', pcall(unpack,t,0,5) );
print( 'pcall(unpack,t,0,6)', pcall(unpack,t,0,6) );
print( 'pcall(unpack,t,0,7)', pcall(unpack,t,0,7) );
print( 'pcall(unpack,t,-1)', pcall(unpack,t,-1) );
print( 'pcall(unpack,t,-1,5)', pcall(unpack,t,-1,5) );
print( 'pcall(unpack,t,-1,6)', pcall(unpack,t,-1,6) );
print( 'pcall(unpack,t,-1,7)', pcall(unpack,t,-1,7) );
print( 'pcall(unpack,t,2,4)', pcall(unpack,t,2,4) );
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
print( 'pcall(unpack,t,2,8)', pcall(unpack,t,2,8) );
print( 'pcall(unpack,t,2,2)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,1)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
t[0] = 'zz'
t[-1] = 'yy'
t[-2] = 'xx'
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
print( 'pcall(unpack,t,"3")', pcall(unpack,t,"3") );
print( 'pcall(unpack,t,"a")', pcall(unpack,t,"a") );
print( 'pcall(unpack,t,function() end)', pcall(unpack,t,function() end) );
-- _VERSION
print( '_VERSION', type(_VERSION) )

View File

@@ -80,10 +80,10 @@ local echo = function(msg,...)
return ...
end
local echocr = function(...)
echo('(echocr) first args', unpack(arg,1,arg.n))
echo('(echocr) first args', table.unpack(arg,1,arg.n))
local a = arg
while true do
a = { echo( '(echoch) yield returns', coroutine.yield( unpack(a) ) ) }
a = { echo( '(echoch) yield returns', coroutine.yield( table.unpack(a) ) ) }
end
end
local c = coroutine.create( echocr )

View File

@@ -4,17 +4,6 @@ local e,f,g,h,s
print( 'has debug', debug~=nil )
if not debug then error( 'no debug' ) end
print( '----- debug.getfenv, debug.setfenv' )
f = function(a)
return 'f:'..tostring(a)..'|'..tostring(b)
end
s,e,g = pcall( debug.getfenv, f )
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
s,e,g = pcall( debug.setfenv, f, {b='def'} )
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
s,e,g = pcall( debug.getfenv, f )
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
print( '----- debug.getlocal, debug.setlocal' )
h = function(v,i,n)

0
test/lua/errors/abc.txt Normal file
View File

View File

@@ -122,7 +122,7 @@ local function expand(argsets, typesets, ...)
local s,v = split(typesets)
for i=1,(v.n or #v) do
expand(argsets, s, v[i], unpack(arg,1,arg.n))
expand(argsets, s, v[i], table.unpack(arg,1,arg.n))
end
return argsets
end
@@ -133,13 +133,13 @@ local function arglists(typesets)
end
function lookup( name )
return loadstring('return '..name)()
return load('return '..name)()
end
function invoke( name, arglist )
local s,c = pcall(lookup, name)
if not s then return s,c end
return pcall(c, unpack(arglist,1,arglist.n or #arglist))
return pcall(c, table.unpack(arglist,1,arglist.n or #arglist))
end
-- messages, banners

View File

@@ -27,11 +27,6 @@ banner('error')
--checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
--checkallerrors('error', {{123},{nil,1,2,n=3}}, 123)
-- getfenv
banner('getfenv')
checkallpass('getfenv', {{nil,print,function()end,0,1,2,n=5}})
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument')
-- getmetatable
banner('getmetatable')
checkallpass('getmetatable', {notanil})
@@ -56,13 +51,13 @@ banner('loadfile')
--checkallpass('loadfile', {{'args.lua'}})
--checkallerrors('loadfile', {nonstring}, 'bad argument')
-- loadstring
banner('loadstring')
checkallpass('loadstring', {{'return'}})
checkallpass('loadstring', {{'return'},{'mychunk'}})
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('loadstring', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
-- load
banner('load')
checkallpass('load', {{'return'}})
checkallpass('load', {{'return'},{'mychunk'}})
checkallpass('load', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('load', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('load', {{'return'},{afunction,atable}}, 'bad argument')
-- next
banner('next')
@@ -113,18 +108,6 @@ banner('select')
checkallpass('select', {{anumber,'#'},anylua})
checkallerrors('select', {notanumber}, 'bad argument')
-- setfenv
banner('setfenv')
local g = _G
checkallpass('setfenv', {{function()end},sometable})
checkallerrors('setfenv', {{-1, '-2'},{g}}, 'level must be non-negative')
checkallerrors('setfenv', {{10, '11'},{g}}, 'invalid level')
checkallerrors('setfenv', {{rawset},{g}}, 'cannot change environment of given object')
checkallerrors('setfenv', {{atable,athread,aboolean,astring},{g}}, 'bad argument')
checkallerrors('setfenv', {notafunction}, 'bad argument')
checkallerrors('setfenv', {anylua}, 'bad argument')
checkallerrors('setfenv', {{function()end},notatable}, 'bad argument')
-- setmetatable
banner('setmetatable')
checkallpass('setmetatable', {sometable,sometable})
@@ -153,15 +136,6 @@ checkallpass('type',{notanil})
checkallpass('type',{anylua,{'anchor'}})
checkallerrors('type',{},'bad argument')
-- unpack
banner('unpack')
checkallpass('unpack',{sometable})
checkallpass('unpack',{sometable,{3,'5'}})
checkallpass('unpack',{sometable,{3,'5'},{1.25,'7'}})
checkallerrors('unpack',{notatable,somenumber,somenumber},'bad argument')
checkallerrors('unpack',{sometable,nonnumber,somenumber},'bad argument')
checkallerrors('unpack',{sometable,somenumber,nonnumber},'bad argument')
-- xpcall
banner('xpcall')
checkallpass('xpcall', {notanil,nonfunction})

View File

@@ -19,28 +19,3 @@ banner('package.seeall')
checkallpass('package.seeall',{sometable})
checkallerrors('package.seeall',{notatable},'bad argument')
-- module tests - require special rigging
banner('module')
checkallerrors('module',{{20001},{nil,package.seeall,n=2},{nil,function()end,n=2}},"'module' not called from a Lua function")
checkallerrors('module',{{'testmodule1'},{nil,'pqrs',aboolean,athread,atable}},"'module' not called from a Lua function")
checkallerrors('module',{{aboolean,atable,function() end}},'bad argument')
checkallerrors('module',{{aboolean,atable,function() end},{package.seeall}},'bad argument')
-- enclose each invokation in its own function
function invoke( name, arglist )
assert( name=='module', 'module rig used for '..name )
local func = function()
module( unpack(arglist,1,arglist.n or #arglist) )
end
return pcall( func )
end
checkallpass('module',{{'foo1',20001}})
checkallpass('module',{{'foo2',20002},{package.seeall}})
checkallpass('module',{{'foo3',20003},{package.seeall},{function() end}})
checkallerrors('module',{{aboolean,atable,function() end}},'bad argument')
checkallerrors('module',{{aboolean,atable,function() end},{package.seeall}},'bad argument')
checkallerrors('module',{{'testmodule2'},{'pqrs'}},'attempt to call')
checkallerrors('module',{{'testmodule3'},{aboolean}},'attempt to call')
checkallerrors('module',{{'testmodule4'},{athread}},'attempt to call')
checkallerrors('module',{{'testmodule5'},{atable}},'attempt to call')

View File

View File

@@ -63,4 +63,13 @@ function table_set_nil_key(tbl,val) tbl[nil]=val end
checkallpass('table_set',{sometable,notanil,anylua})
checkallerrors('table_set_nil_key',{sometable,anylua},'table index')
-- table.unpack
banner('table.unpack')
checkallpass('table.unpack',{sometable})
checkallpass('table.unpack',{sometable,{3,'5'}})
checkallpass('table.unpack',{sometable,{3,'5'},{1.25,'7'}})
checkallerrors('table.unpack',{notatable,somenumber,somenumber},'bad argument')
checkallerrors('table.unpack',{sometable,nonnumber,somenumber},'bad argument')
checkallerrors('table.unpack',{sometable,somenumber,nonnumber},'bad argument')

Binary file not shown.

View File

@@ -33,5 +33,5 @@ t[200] = [[
local s = table.concat(t)
print(s)
f = loadstring(s)
f = load(s)
f()

View File

@@ -100,9 +100,9 @@ end
local function eval( expr, script )
script = script or ('return '..expr)
local s,a,b = loadstring( script, 'expr' )
local s,a,b = load( script, 'expr' )
if s then print( expr, pcall( s ) )
else print( expr, 'loadstring:', a ) end
else print( expr, 'load:', a ) end
end
-- misc tests
@@ -191,7 +191,7 @@ end
-- random tests
print("----------- Random number tests")
local function testrandom(string,lo,hi)
local c,e = loadstring('return '..string)
local c,e = load('return '..string)
for i=1,5 do
local s,e = pcall(c)
if s then

View File

@@ -9,7 +9,7 @@ local function fannkuch(n)
-- Print max. 30 permutations.
if check < 30 then
if not p[n] then return maxflips end -- Catch n = 0, 1, 2.
io.write(unpack(p)); io.write("\n")
io.write(table.unpack(p)); io.write("\n")
check = check + 1
end
-- Copy and flip.

View File

@@ -1,18 +1,39 @@
#!/bin/bash
#unzip -o luaj3.0-tests.zip
#
# unpack the luaj test archive, compile and run it locally, and repack the results
# unzip existing archive
unzip -n luaj3.0-tests.zip
rm *.lc *.out */*.lc */*.out
# compile tests for compiler and save binary files
for DIR in "lua5.2.1-tests" "regressions"; do
cd ${DIR}
FILES=`ls -1 *.lua | awk 'BEGIN { FS="." } ; { print $1 }'`
for FILE in $FILES ; do
echo 'compiling' `pwd` $FILE
luac ${FILE}.lua
mv luac.out ${FILE}.lc
done
cd ..
done
# run test lua scripts and save output
for DIR in "errors" "perf" "."; do
cd ${DIR}
FILES=`ls -1 *.lua | awk 'BEGIN { FS="." } ; { print $1 }'`
echo "FILES" $FILES
for FILE in $FILES ; do
echo "executing ${FILE}.lua"
luac ${FILE}.lua
mv luac.out ${FILE}.lc
echo 'executing' `pwd` $FILE
lua ${FILE}.lua > ${FILE}.out
done
rm abc.txt
cd ..
done
cd lua
rm -f luaj3.0-tests.zip
# create new zipfile
rm -f luaj3.0-tests.zip regressions
zip -9 luaj3.0-tests.zip *.lua *.lc *.out */*.lua */*.lc */*.out
# cleanup
rm *.out */*.lc */*.out
rm -r lua5.2.1-tests

View File

@@ -144,7 +144,7 @@ strtests('lower', string.lower, s )
strtests('upper', string.upper, s )
strtests('reverse', string.reverse, s )
strtests('char', string.char, 92, 60, 61, 93 )
strtests('dump', string.dump, loadstring('print("hello, world")', 'sample') )
strtests('dump', string.dump, load('print("hello, world")', 'sample') )
-- floating point formats (not supported yet)

View File

@@ -164,8 +164,16 @@ testbothpairs(t)
--]]
-- tests of setlist table constructors
-- length and unpack are tested elsewhere
-- length is tested elsewhere
print('----- unpack tests -------')
local unpack = table.unpack
print( 'pcall(unpack)', pcall(unpack) );
print( 'pcall(unpack,nil)', pcall(unpack,nil) );
print( 'pcall(unpack,"abc")', pcall(unpack,"abc") );
print( 'pcall(unpack,1)', pcall(unpack,1) );
print( 'unpack({"aa"})', unpack({"aa"}) );
print( 'unpack({"aa","bb"})', unpack({"aa","bb"}) );
print( 'unpack({"aa","bb","cc"})', unpack({"aa","bb","cc"}) );
local function a(...) return ... end
print('unpack -',unpack({}))
print('unpack a',unpack({'a'}))
@@ -195,6 +203,42 @@ print('unpack (..b)',unpack({a(nil, nil, 'b')},1,3))
print('unpack (a..)',unpack({a('a', nil, nil)},1,3))
print('unpack (.b.)',unpack({a(nil, 'b', nil)},1,3))
print('unpack (...)',unpack({a(nil, nil, nil)},1,3))
local t = {"aa","bb","cc","dd","ee","ff"}
print( 'pcall(unpack,t)', pcall(unpack,t) );
print( 'pcall(unpack,t,2)', pcall(unpack,t,2) );
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
print( 'pcall(unpack,t,1)', pcall(unpack,t,1) );
print( 'pcall(unpack,t,1,5)', pcall(unpack,t,1,5) );
print( 'pcall(unpack,t,1,6)', pcall(unpack,t,1,6) );
print( 'pcall(unpack,t,1,7)', pcall(unpack,t,1,7) );
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
print( 'pcall(unpack,t,0,5)', pcall(unpack,t,0,5) );
print( 'pcall(unpack,t,0,6)', pcall(unpack,t,0,6) );
print( 'pcall(unpack,t,0,7)', pcall(unpack,t,0,7) );
print( 'pcall(unpack,t,-1)', pcall(unpack,t,-1) );
print( 'pcall(unpack,t,-1,5)', pcall(unpack,t,-1,5) );
print( 'pcall(unpack,t,-1,6)', pcall(unpack,t,-1,6) );
print( 'pcall(unpack,t,-1,7)', pcall(unpack,t,-1,7) );
print( 'pcall(unpack,t,2,4)', pcall(unpack,t,2,4) );
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
print( 'pcall(unpack,t,2,8)', pcall(unpack,t,2,8) );
print( 'pcall(unpack,t,2,2)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,1)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
t[0] = 'zz'
t[-1] = 'yy'
t[-2] = 'xx'
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
print( 'pcall(unpack,t,"3")', pcall(unpack,t,"3") );
print( 'pcall(unpack,t,"a")', pcall(unpack,t,"a") );
print( 'pcall(unpack,t,function() end)', pcall(unpack,t,function() end) );
-- misc tests
print('----- misc table initializer tests -------')

View File

@@ -63,8 +63,8 @@ local function all(f)
for n=0,3 do
t = {}
for m=1,5 do
print( "--f, n, unpack(t)", f, n, unpack(t) )
print( pcall( f, n, unpack(t)) )
print( "--f, n, table.unpack(t)", f, n, table.unpack(t) )
print( pcall( f, n, table.unpack(t)) )
t[m] = m
end
end