Fix load(func) when mutiple string fragments are supplied by calls to func

This commit is contained in:
James Roseborough
2012-01-21 17:36:03 +00:00
parent 26ed1ef392
commit c46ee6b9bd
4 changed files with 38 additions and 15 deletions

View File

@@ -95,6 +95,23 @@ public class OrphanedThreadTest extends TestCase {
doTest(LuaValue.TRUE, LuaValue.ZERO);
}
public void testCollectOrphanedLoadCloasureThread() throws Exception {
String script =
"t = { \"print \", \"'hello, \", \"world'\", }\n" +
"i = 0\n" +
"arg = ...\n" +
"f = function()\n" +
" i = i + 1\n" +
" print('in load-closure, arg is', arg, 'next is', t[i])\n" +
" arg = coroutine.yield(1)\n" +
" return t[i]\n" +
"end\n" +
"load(f)()\n";
LuaC.install();
function = LoadState.load(new ByteArrayInputStream(script.getBytes()), "script", env);
doTest(LuaValue.TRUE, LuaValue.ONE);
}
private void doTest(LuaValue status2, LuaValue value2) throws Exception {
luathread = new LuaThread(function, env);
luathr_ref = new WeakReference(luathread);
@@ -103,11 +120,11 @@ public class OrphanedThreadTest extends TestCase {
// resume two times
Varargs a = luathread.resume(LuaValue.valueOf("foo"));
assertEquals(LuaValue.TRUE, a.arg1());
assertEquals(LuaValue.ONE, a.arg(2));
assertEquals(LuaValue.TRUE, a.arg1());
a = luathread.resume(LuaValue.valueOf("bar"));
assertEquals(status2, a.arg1());
assertEquals(value2, a.arg(2));
assertEquals(status2, a.arg1());
// drop strong references
luathread = null;

View File

@@ -52,6 +52,12 @@ for k,v in ipairs({aa='aaa',bb='bbb','one','two'}) do print('ipairs4',k,v)end
for k,v in ipairs({[30]='30',[20]='20'}) do print('ipairs5',k,v)end
-- load
t = { "print ", "'table ", "loaded'", "", " print'after empty string'" }
i = 0
f = function() i = i + 1; return t[i]; end
c,e = load(f)
if c then print('load: ', pcall(c)) else print('load failed:', e) end
-- loadfile
-- loadstring
local lst = "print(3+4); return 8"
@@ -303,3 +309,4 @@ print( 'pcall(xpcall(badfunc,errfunc))', pcall(xpcall,badfunc,errfunc) )
print( 'pcall(xpcall(badfunc,badfunc))', pcall(xpcall,badfunc,badfunc) )
print( 'pcall(xpcall(wrappedbad))', pcall(xpcall,wrappedbad) )
print( 'xpcall(wrappedbad,errfunc)', xpcall(wrappedbad,errfunc) )