From e1d6ddf99c022d92714930c7074101ca7a22e6d6 Mon Sep 17 00:00:00 2001 From: Ian Farmer Date: Sat, 21 Jul 2007 04:44:22 +0000 Subject: [PATCH] New autoload and math test cases. Currently autoload does not work because the GETGLOBAL instruction does not handle the case where a metatable method is invoked. --- src/main/java/lua/GlobalState.java | 4 ++++ src/test/java/lua/LuaJTest.java | 8 ++++++++ src/test/res/autoload.lua | 11 +++++++++++ src/test/res/autoload.luac | Bin 0 -> 605 bytes src/test/res/math.lua | 7 +++++++ src/test/res/math.luac | Bin 0 -> 397 bytes 6 files changed, 30 insertions(+) create mode 100644 src/test/res/autoload.lua create mode 100644 src/test/res/autoload.luac create mode 100644 src/test/res/math.lua create mode 100644 src/test/res/math.luac diff --git a/src/main/java/lua/GlobalState.java b/src/main/java/lua/GlobalState.java index 84723cf0..35f6e1cf 100644 --- a/src/main/java/lua/GlobalState.java +++ b/src/main/java/lua/GlobalState.java @@ -26,6 +26,10 @@ public class GlobalState { private static LTable _G; static { + resetGlobals(); + } + + static void resetGlobals() { _G = new LTable(); _G .put( "_G", _G ); Builtin.addBuiltins( _G ); diff --git a/src/test/java/lua/LuaJTest.java b/src/test/java/lua/LuaJTest.java index 1f0c08dc..fd566be2 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 testAutoload() throws IOException, InterruptedException { + runTest( "autoload" ); + } + public void testBoolean() throws IOException, InterruptedException { runTest( "boolean" ); } @@ -68,6 +72,10 @@ public class LuaJTest extends TestCase { } private void runTest( String testName ) throws IOException, InterruptedException { + + // Reset the _G table just in case some test mucks with it + GlobalState.resetGlobals(); + // add LuaJava bindings LuaJava.install(); diff --git a/src/test/res/autoload.lua b/src/test/res/autoload.lua new file mode 100644 index 00000000..723e53ed --- /dev/null +++ b/src/test/res/autoload.lua @@ -0,0 +1,11 @@ +local function autoload(table, key) + local chunk = loadfile("/"..key..".luac") + table[key] = chunk() +end + +autoload_mt = { __index = autoload } + +setmetatable(_G, autoload_mt) + +print("square root of 9.0 is ", math.sqrt(9.0)) +print("math.pi=", math.pi); diff --git a/src/test/res/autoload.luac b/src/test/res/autoload.luac new file mode 100644 index 0000000000000000000000000000000000000000..e49e9fc43b3bd9d2f4592b648f1b368a77d22484 GIT binary patch literal 605 zcmZ`$Jxc>Y5Pf@Yg7K?TECe~kI@($YYY{@k#y$|%oTyoh1?KVaJg+JyZ#D8Fy zALG0`4lLrp+xd92v$Hc-FPVLX(pn$l41lqjOD2gOG$)xAzmlMKA?B^%*#I4Q-xj;& zfprdS#qJufT2NRSg{@ck&NoV_06Rc+jpP@iK(22{*NF zR9eeL>c9#jH%2!^k!;T6$FlM~mR?Jt)-(guk3_8n8zYDEcv=BJW~DwoR4$R7_h{rE z{1wX=l{w2{%$@@Y-IXnKxP5T})+DhHtWkkI(B_BB8HfS4PG%f^&@Fss^heojT;wu? f!tF7WYz5BvFWAd};Fk7*^WhuS@`}NoOMvnV^_Edm literal 0 HcmV?d00001 diff --git a/src/test/res/math.lua b/src/test/res/math.lua new file mode 100644 index 00000000..13dc6b8d --- /dev/null +++ b/src/test/res/math.lua @@ -0,0 +1,7 @@ +local mathClass = luajava.bindClass("java.lang.Math") + +local function sqrt(x) + return mathClass:sqrt(x) +end + +return { sqrt = sqrt; pi = mathClass.PI } diff --git a/src/test/res/math.luac b/src/test/res/math.luac new file mode 100644 index 0000000000000000000000000000000000000000..6152d02fe01395795bb07ce6d180df7134b77d40 GIT binary patch literal 397 zcmZ`#OKJi^6s*>#5fktLksM*p(4rgBfF3}hMMy?QNgNfI9e3ssIg2aLWtC${6nstb zzFqaYpZn`Dgfp`m>Hz#atlpDs9T@*w$(|Tih^qH!MW7ksrkD0N^SzH>N8iH!fZY$^ zUJy}bpQHfEW?>Ux;-938X*&yf4r?$~Bgw+zEqSFbOd|Q`as?|h`bY~u=)y6TsjMOA zU{dH1Jsfy|5uzK@OI`DSY)p!MRK3BOjkOZ7B`*B*+E?FE?5jTz>woC3@Nfs>yk?R5 NBcWU8hw2e3$WCc-Evx_l literal 0 HcmV?d00001