Fix upvalues that allow closures to work properly.
This commit is contained in:
@@ -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] );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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+")";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
function sum(a,b,c,d) -- "sum" method
|
||||
local d = d or 0
|
||||
return a+b+c+d -- return sum
|
||||
end
|
||||
print( sum( 1, 2, 3, 4 ) )
|
||||
@@ -6,5 +8,22 @@ 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) )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user