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:
@@ -128,7 +128,7 @@ public final class LuaJava extends LFunction {
|
|||||||
LValue v = CoerceJavaToLua.coerce( o );
|
LValue v = CoerceJavaToLua.coerce( o );
|
||||||
vm.push( v );
|
vm.push( v );
|
||||||
} catch (NoSuchFieldException nsfe) {
|
} catch (NoSuchFieldException nsfe) {
|
||||||
vm.setResult( new LMethod(m_instance,clazz,s) );
|
vm.push( new LMethod(m_instance,clazz,s) );
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import lua.StackState;
|
import lua.StackState;
|
||||||
|
import lua.addon.luacompat.LuaCompat;
|
||||||
import lua.addon.luajava.LuaJava;
|
import lua.addon.luajava.LuaJava;
|
||||||
import lua.io.Closure;
|
import lua.io.Closure;
|
||||||
import lua.io.LoadState;
|
import lua.io.LoadState;
|
||||||
@@ -20,6 +21,9 @@ public class LuaJavaAppRunner {
|
|||||||
|
|
||||||
public static void main( String[] args ) throws IOException {
|
public static void main( String[] args ) throws IOException {
|
||||||
|
|
||||||
|
// add LuaCompat bindings
|
||||||
|
LuaCompat.install();
|
||||||
|
|
||||||
// add LuaJava bindings
|
// add LuaJava bindings
|
||||||
LuaJava.install();
|
LuaJava.install();
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,11 @@ public class LuaJTest extends TestCase {
|
|||||||
public void testBoolean() throws IOException, InterruptedException {
|
public void testBoolean() throws IOException, InterruptedException {
|
||||||
runTest( "boolean" );
|
runTest( "boolean" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCalls() throws IOException, InterruptedException {
|
||||||
|
runTest( "calls" );
|
||||||
|
}
|
||||||
|
|
||||||
public void testCoercions() throws IOException, InterruptedException {
|
public void testCoercions() throws IOException, InterruptedException {
|
||||||
runTest( "coercions" );
|
runTest( "coercions" );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
|
-- Clear out builtin math package
|
||||||
|
math = nil
|
||||||
|
|
||||||
local function autoload(table, key)
|
local function autoload(table, key)
|
||||||
local chunk = loadfile("/"..key..".luac")
|
local chunk = loadfile(key..".luac")
|
||||||
table[key] = chunk()
|
table[key] = chunk()
|
||||||
end
|
end
|
||||||
|
|
||||||
autoload_mt = { __index = autoload }
|
setmetatable(_G, { __index = autoload } )
|
||||||
|
|
||||||
setmetatable(_G, autoload_mt)
|
|
||||||
|
|
||||||
|
-- local result = math.sqrt(9.0)
|
||||||
|
-- print("x=", result)
|
||||||
print("square root of 9.0 is ", math.sqrt(9.0))
|
print("square root of 9.0 is ", math.sqrt(9.0))
|
||||||
print("math.pi=", math.pi);
|
print("math.pi=", math.pi);
|
||||||
|
|||||||
Binary file not shown.
4
src/test/res/calls-expected.out
Normal file
4
src/test/res/calls-expected.out
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
15
|
||||||
|
15
|
||||||
|
1.2246467991473532E-16
|
||||||
|
1.2246467991473532E-16
|
||||||
24
src/test/res/calls.lua
Normal file
24
src/test/res/calls.lua
Normal 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
BIN
src/test/res/calls.luac
Normal file
Binary file not shown.
Reference in New Issue
Block a user