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.
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
11
src/test/res/autoload.lua
Normal file
11
src/test/res/autoload.lua
Normal file
@@ -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);
|
||||
BIN
src/test/res/autoload.luac
Normal file
BIN
src/test/res/autoload.luac
Normal file
Binary file not shown.
7
src/test/res/math.lua
Normal file
7
src/test/res/math.lua
Normal file
@@ -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 }
|
||||
BIN
src/test/res/math.luac
Normal file
BIN
src/test/res/math.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user