From 45964d7e2224a48dd3223019f1307052e7bdb668 Mon Sep 17 00:00:00 2001 From: Ian Farmer Date: Mon, 9 Jul 2007 01:43:34 +0000 Subject: [PATCH] Add simple test for correct upvalue handling. --- src/test/java/lua/LuaJTest.java | 4 ++++ src/test/res/upvalues.lua | 25 +++++++++++++++++++++++++ src/test/res/upvalues.luac | Bin 0 -> 937 bytes 3 files changed, 29 insertions(+) create mode 100644 src/test/res/upvalues.lua create mode 100644 src/test/res/upvalues.luac diff --git a/src/test/java/lua/LuaJTest.java b/src/test/java/lua/LuaJTest.java index 3d22b0b0..2147ae5b 100644 --- a/src/test/java/lua/LuaJTest.java +++ b/src/test/java/lua/LuaJTest.java @@ -43,6 +43,10 @@ public class LuaJTest extends TestCase { runTest( "test7" ); } + public void testUpvalues() throws IOException, InterruptedException { + runTest( "upvalues" ); + } + private void runTest( String testName ) throws IOException, InterruptedException { // add LuaJava bindings LuaJava.install(); diff --git a/src/test/res/upvalues.lua b/src/test/res/upvalues.lua new file mode 100644 index 00000000..ea760070 --- /dev/null +++ b/src/test/res/upvalues.lua @@ -0,0 +1,25 @@ +function test() + local x = 5 + function f() + x = x + 1 + return x + end + function g() + x = x - 1 + return x + end + print(f()) + print(g()) + return f, g +end + +f1, g1 = test() +print("f1()=", f1()) +print("g1()=", g1()) + +f2, g2 = test() +print("f2()=", f2()) +print("g2()=", g2()) + +print("g1()=", g1()) +print("f1()=", f1()) diff --git a/src/test/res/upvalues.luac b/src/test/res/upvalues.luac new file mode 100644 index 0000000000000000000000000000000000000000..4ad04e3d838b824654d13837d93bbe28f85a95df GIT binary patch literal 937 zcma)4%SyvQ6upy-wrVRrswkGOT-c4!?!|E--MDctLcpd7MT%|220cLMwhUS8+>2f7H1SkLGLE*Ix!;af0HVtmW zeqDpRA|`wAbOf8wSim9g6z=Qu!r_?if5&hak1cS5&1lUS-jM^j0KsjUMextJ6QKhg vq6_W8Z_{)pI{;|>JNu`5;34**W3Vnp53vwO&@qk?i*bTjj8nvZ1H#VMNsCDq literal 0 HcmV?d00001