Fix a few VM issues which were causing subtle failures in the test cases.

Includes a new VM method, newCall, which must be called before pushing
a call onto the stack to make sure that base is set correctly.
A couple of weird issues remain with autoload.lua.
This commit is contained in:
Ian Farmer
2007-09-04 01:52:33 +00:00
parent 0f81c4deaf
commit 75fb975410
8 changed files with 45 additions and 6 deletions

View File

@@ -128,7 +128,7 @@ public final class LuaJava extends LFunction {
LValue v = CoerceJavaToLua.coerce( o );
vm.push( v );
} catch (NoSuchFieldException nsfe) {
vm.setResult( new LMethod(m_instance,clazz,s) );
vm.push( new LMethod(m_instance,clazz,s) );
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@@ -3,6 +3,7 @@ import java.io.IOException;
import java.io.InputStream;
import lua.StackState;
import lua.addon.luacompat.LuaCompat;
import lua.addon.luajava.LuaJava;
import lua.io.Closure;
import lua.io.LoadState;
@@ -20,6 +21,9 @@ public class LuaJavaAppRunner {
public static void main( String[] args ) throws IOException {
// add LuaCompat bindings
LuaCompat.install();
// add LuaJava bindings
LuaJava.install();

View File

@@ -52,6 +52,10 @@ public class LuaJTest extends TestCase {
runTest( "boolean" );
}
public void testCalls() throws IOException, InterruptedException {
runTest( "calls" );
}
public void testCoercions() throws IOException, InterruptedException {
runTest( "coercions" );
}

View File

@@ -1,11 +1,14 @@
-- Clear out builtin math package
math = nil
local function autoload(table, key)
local chunk = loadfile("/"..key..".luac")
local chunk = loadfile(key..".luac")
table[key] = chunk()
end
autoload_mt = { __index = autoload }
setmetatable(_G, autoload_mt)
setmetatable(_G, { __index = autoload } )
-- local result = math.sqrt(9.0)
-- print("x=", result)
print("square root of 9.0 is ", math.sqrt(9.0))
print("math.pi=", math.pi);

Binary file not shown.

View File

@@ -0,0 +1,4 @@
15
15
1.2246467991473532E-16
1.2246467991473532E-16

24
src/test/res/calls.lua Normal file
View File

@@ -0,0 +1,24 @@
local function f(x)
-- tailcall to a builtin
return math.sin(x)
end
local function factorial(i)
local function helper(sum, n)
if n <= 0 then
return sum
else
-- tail call to a nested Lua function
return helper(n + sum, n - 1)
end
end
return helper(0, i)
end
local result1 = factorial(5)
print(result1)
print(factorial(5))
local result2 = f(math.pi)
print(result2)
print(f(math.pi))

BIN
src/test/res/calls.luac Normal file

Binary file not shown.