diff --git a/src/test/java/org/luaj/vm/LuaJTest.java b/src/test/java/org/luaj/vm/LuaJTest.java index 452538e0..6c277f96 100644 --- a/src/test/java/org/luaj/vm/LuaJTest.java +++ b/src/test/java/org/luaj/vm/LuaJTest.java @@ -74,6 +74,10 @@ public class LuaJTest extends TestCase { runTest( "errors" ); } + public void testLoops() throws IOException, InterruptedException { + runTest( "loops" ); + } + public void testMathLib() throws IOException, InterruptedException { runTest( "mathlib" ); } diff --git a/src/test/res/loops.lua b/src/test/res/loops.lua new file mode 100644 index 00000000..431374c8 --- /dev/null +++ b/src/test/res/loops.lua @@ -0,0 +1,22 @@ +-- This script tests the "generic" for loop with a script iterator. + +local function stuff() + local function i(o) + if o.counter > 3 then + return nil + else + local v = o.counter + o.counter = v + 1 + return v + end + end + return i, { counter=1 } +end + +local function testfor() + for x in stuff() do + print(x) + end +end + +testfor() diff --git a/src/test/res/loops.luac b/src/test/res/loops.luac new file mode 100644 index 00000000..c7cbe1a9 Binary files /dev/null and b/src/test/res/loops.luac differ