Various changes to bring pm.lua test closer to passing:

* New and complete character class support
 * string.gsub implemented
 * rawset implemented
 * lua_call added (based on lua_pcall)
 * lua_pop added
 * newCall removed; luaGetTable and luaSetTable in LFunction updated to
   use lua_call instead.
 * StandardTest changed to avoid an ArrayIndexOutOfBoundsException

Unfortunately I discovered a problem where execute() will loop around too
many times and call exec() with a call frame that has already completed.
This might be due to the lack of the "tailcalls" field in our CallInfo class
that the C version maintains?
This commit is contained in:
Ian Farmer
2007-09-24 04:35:53 +00:00
parent f801e648bb
commit ec11c472c8
8 changed files with 269 additions and 53 deletions

View File

@@ -15,6 +15,7 @@ import junit.framework.TestSuite;
import lua.Builtin;
import lua.StackState;
import lua.addon.luacompat.LuaCompat;
import lua.debug.DebugStackState;
import lua.io.Closure;
import lua.io.LoadState;
import lua.io.Proto;
@@ -79,7 +80,7 @@ public class StandardTest extends TestCase {
// the garbage collector. Until we implement that, remove the
// built-in collectgarbage function.
GlobalState.getGlobalsTable().put( "collectgarbage", LNil.NIL );
StackState state = new StackState();
StackState state = new DebugStackState();
Closure c = new Closure( state, code );
ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -88,13 +89,15 @@ public class StandardTest extends TestCase {
try {
state.doCall( c, new LValue[0] );
} catch ( RuntimeException exn ) {
StackTraceElement[] stackTrace = new StackTraceElement[state.cc+1];
for ( int i = 0; i <= state.cc; ++i ) {
final int ncalls = Math.min( state.calls.length, state.cc+1 );
StackTraceElement[] stackTrace = new StackTraceElement[ncalls];
for ( int i = 0; i < ncalls; ++i ) {
CallInfo call = state.calls[i];
Proto p = call.closure.p;
int line = p.lineinfo[call.pc-1];
String func = call.closure.luaAsString().toJavaString();
stackTrace[state.cc - i] = new StackTraceElement(getName(), func, getName()+".lua", line );
stackTrace[ncalls - i - 1] = new StackTraceElement(getName(), func, getName()+".lua", line );
}
RuntimeException newExn = new RuntimeException( exn );

View File

@@ -1,3 +1,7 @@
print( string.find( 'alo alx 123 b\0o b\0o', '(..*) %1' ) )
print( string.find( 'aloALO', '%l*' ) )
print( string.find( ' \n isto <20> assim', '%S%S*' ) )
print( string.find( "", "" ) )
print( string.find( "ababaabbaba", "abb" ) )
print( string.find( "ababaabbaba", "abb", 7 ) )
@@ -19,3 +23,23 @@ print( string.byte("hi", -3) )
print( tostring(1234567890123) )
print( tostring(1234567890124) )
print( tostring(1234567890125) )
function f1(s, p)
print(p)
p = string.gsub(p, "%%([0-9])", function (s) return "%" .. (s+1) end)
print(p)
p = string.gsub(p, "^(^?)", "%1()", 1)
print(p)
p = string.gsub(p, "($?)$", "()%1", 1)
print(p)
local t = {string.match(s, p)}
return string.sub(s, t[1], t[#t] - 1)
end
print( f1('alo alx 123 b\0o b\0o', '(..*) %1') )
local function badpat()
print( string.gsub( "alo", "(.)", "%2" ) )
end
print( pcall( badpat ) )

Binary file not shown.