Fix upvalues that allow closures to work properly.

This commit is contained in:
James Roseborough
2007-06-14 04:09:57 +00:00
parent 4b7bbc1d8e
commit 14108aee87
4 changed files with 37 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ public class Closure extends LValue {
this.p = p;
upVals = new UpVal[p.nups];
for ( int i=0; i<p.nups; i++ )
upVals[i] = new UpVal();
upVals[i] = new UpVal( p.upvalues[i] );
}

View File

@@ -1,5 +1,20 @@
package lua.io;
import lua.value.LNil;
import lua.value.LString;
import lua.value.LValue;
public class UpVal {
private LString name;
public LValue value;
public UpVal( LString string ) {
this.name = string;
}
public String toString() {
return "up("+name+")";
}
}

View File

@@ -1,7 +1,7 @@
#!/bin/bash
LUA_HOME=/cygdrive/c/programs/lua5.1
TESTS="test1 test2 test3 test4 test5"
TESTS="test3"
TESTS="test2"
for x in $TESTS
do
echo compiling $x

View File

@@ -1,10 +1,29 @@
function sum(a,b,c,d) -- "sum" method
return a+b+c+d -- return sum
local d = d or 0
return a+b+c+d -- return sum
end
print( sum( 1, 2, 3, 4 ) )
print( sum( 5, 6, 7 ) )
print( sum( 9, 10, 11, 12, 13, 14 ) )
print( sum( sum(1,2,3,4), sum(5,6,7), sum(9,10,11,12,13,14), 15 ) )
function myfunc(x)
return x*x;
end
print( myfunc(0.1) )
do
local oldMyfunc = myfunc
local k = 55
myfunc = function (x)
local a = k + oldMyfunc(x)
k = k + 5
return a
end
end
print( myfunc(0.1) )
print( myfunc(0.1) )