Replace settop(0) with resettop()

This commit is contained in:
James Roseborough
2007-11-16 19:19:13 +00:00
parent d7ae4a809c
commit 45f483f706
8 changed files with 46 additions and 46 deletions

View File

@@ -100,12 +100,12 @@ public class BaseLib extends LFunction {
}
private static void setResult( LuaState vm, LValue value ) {
vm.settop(0);
vm.resettop();
vm.pushlvalue( value );
}
private static void setErrorResult( LuaState vm, String message ) {
vm.settop(0);
vm.resettop();
vm.pushnil();
vm.pushstring( message );
}
@@ -120,20 +120,20 @@ public class BaseLib extends LFunction {
stdout.print( vm.tostring(i) );
}
stdout.println();
vm.settop(0);
vm.resettop();
break;
}
case PAIRS:
case IPAIRS: {
LValue v = vm.topointer(2);
LValue r = v.luaPairs(id==PAIRS);
vm.settop(0);
vm.resettop();
vm.pushlvalue( r );
break;
}
case GETMETATABLE: {
if ( 0 == vm.getmetatable(2) ) {
vm.settop(0);
vm.resettop();
vm.pushnil();
} else {
vm.insert(1);
@@ -153,7 +153,7 @@ public class BaseLib extends LFunction {
if ( vm.gettop() < 2 )
vm.error("bad argument #1 to '?' (value expected)");
LValue v = vm.topointer(2);
vm.settop(0);
vm.resettop();
vm.pushlstring( v.luaGetTypeName() );
break;
}
@@ -187,7 +187,7 @@ public class BaseLib extends LFunction {
case TONUMBER: {
LValue input = vm.topointer(2);
vm.settop(0);
vm.resettop();
if ( input instanceof LNumber ) {
vm.pushlvalue(input);
} else if ( input instanceof LString ) {
@@ -203,7 +203,7 @@ public class BaseLib extends LFunction {
case RAWGET: {
LValue t = vm.topointer(2);
LValue k = vm.topointer(3);
vm.settop(0);
vm.resettop();
if ( t instanceof LTable ) {
vm.pushlvalue(( (LTable) t ).get( k ));
}
@@ -212,7 +212,7 @@ public class BaseLib extends LFunction {
LValue t = vm.topointer(2);
LValue k = vm.topointer(3);
LValue v = vm.topointer(4);
vm.settop(0);
vm.resettop();
if ( t instanceof LTable ) {
( (LTable) t ).put( k, v );
} else {
@@ -242,11 +242,11 @@ public class BaseLib extends LFunction {
int i = vm.tointeger(2);
if ( i == 0 ) {
vm._G = t;
vm.settop(0);
vm.resettop();
} else {
LClosure c = vm.getStackFrame(i-1).closure;
c.luaSetEnv(t);
vm.settop(0);
vm.resettop();
vm.pushlvalue(c);
}
break;
@@ -256,7 +256,7 @@ public class BaseLib extends LFunction {
break;
case COLLECTGARBAGE:
System.gc();
vm.settop(0);
vm.resettop();
break;
case DOFILE:
dofile(vm);
@@ -271,7 +271,7 @@ public class BaseLib extends LFunction {
if ( vm.gettop() < 2 )
vm.error( "bad argument #1 to '?' (value expected)" );
LValue v = vm.topointer(2);
vm.settop(0);
vm.resettop();
vm.pushlvalue( v.luaAsString() );
break;
}
@@ -288,7 +288,7 @@ public class BaseLib extends LFunction {
i = 1;
if ( n <= 3 )
j = list.luaLength();
vm.settop(0);
vm.resettop();
vm.checkstack(j+1-i);
for ( int k=i; k<=j; k++ )
vm.pushlvalue(list.get(k));
@@ -348,7 +348,7 @@ public class BaseLib extends LFunction {
// return true if laoded, false if error put onto the stack
private static boolean loadis(LuaState vm, InputStream is, String chunkname ) {
try {
vm.settop(0);
vm.resettop();
if ( 0 != vm.load(is, chunkname) ) {
setErrorResult( vm, "cannot load "+chunkname+": "+vm.topointer(-1) );
return false;

View File

@@ -76,7 +76,7 @@ public class MathLib extends LFunction {
}
private static void setResult( LuaState vm, LValue value ) {
vm.settop(0);
vm.resettop();
vm.pushlvalue( value );
}
@@ -135,7 +135,7 @@ public class MathLib extends LFunction {
double v = arg.toJavaDouble();
double intPart = ( v > 0 ) ? Math.floor( v ) : Math.ceil( v );
double fracPart = v - intPart;
vm.settop(0);
vm.resettop();
vm.pushnumber( intPart );
vm.pushnumber( fracPart );
}

View File

@@ -132,7 +132,7 @@ public class PackageLib extends LFunction {
public static void require( LuaState vm ) {
LString modname = vm.tolstring(2);
if ( LOADED.containsKey(modname) ) {
vm.settop(0);
vm.resettop();
vm.pushlvalue( LOADED.get(modname) );
}
else {
@@ -145,7 +145,7 @@ public class PackageLib extends LFunction {
LOADED.put(modname, result);
else if ( ! LOADED.containsKey(modname) )
LOADED.put(modname, result = LBoolean.TRUE);
vm.settop(0);
vm.resettop();
vm.pushlvalue( result );
}
}

View File

@@ -157,7 +157,7 @@ public class StringLib extends LFunction {
final int top = vm.gettop();
int i = posrelat( ( top >= 3 ) ? vm.tointeger(3) : 1, l );
int j = posrelat( ( top >= 4 ) ? vm.tointeger(4) : i, l );
vm.settop(0);
vm.resettop();
if ( i <= 0 )
i = 1;
if ( j > l )
@@ -185,7 +185,7 @@ public class StringLib extends LFunction {
byte[] bytes = new byte[nargs];
for ( int i=0; i<nargs; i++ )
bytes[i] = (byte)( vm.tointeger(i+2) & 0x0FF );
vm.settop(0);
vm.resettop();
vm.pushlstring( bytes );
}
@@ -246,7 +246,7 @@ public class StringLib extends LFunction {
* except as arguments to the q option.
*/
static void format( LuaState vm ) {
vm.settop(0);
vm.resettop();
vm.pushstring( "" );
}
@@ -275,7 +275,7 @@ public class StringLib extends LFunction {
* as this would prevent the iteration.
*/
static void gmatch( LuaState vm ) {
vm.settop(0);
vm.resettop();
vm.pushlvalue( new GMatchAux(vm) );
}
@@ -292,7 +292,7 @@ public class StringLib extends LFunction {
this.soffset = 0;
}
public boolean luaStackCall(LuaState vm) {
vm.settop(0);
vm.resettop();
for ( ; soffset<srclen; soffset++ ) {
int res = ms.match(soffset, 0);
if ( res >=0 ) {
@@ -383,7 +383,7 @@ public class StringLib extends LFunction {
break;
}
lbuf.append( src.substring( soffset, srclen ) );
vm.settop(0);
vm.resettop();
vm.pushlstring( lbuf.toLuaString() );
vm.pushinteger( n );
}
@@ -396,7 +396,7 @@ public class StringLib extends LFunction {
*/
static void len( LuaState vm ) {
int l = vm.tostring(2).length();
vm.settop(0);
vm.resettop();
vm.pushinteger( l );
}
@@ -409,7 +409,7 @@ public class StringLib extends LFunction {
*/
static void lower( LuaState vm ) {
String s = vm.tostring(2).toLowerCase();
vm.settop(0);
vm.resettop();
vm.pushstring( s );
}
@@ -434,7 +434,7 @@ public class StringLib extends LFunction {
static void rep( LuaState vm ) {
LString s = vm.tolstring(2);
int n = vm.tointeger( 3 );
vm.settop(0);
vm.resettop();
if ( n >= 0 ) {
final byte[] bytes = new byte[ s.length() * n ];
int len = s.length();
@@ -456,7 +456,7 @@ public class StringLib extends LFunction {
byte[] b = new byte[n];
for ( int i=0, j=n-1; i<n; i++, j-- )
b[j] = (byte) s.luaByte(i);
vm.settop(0);
vm.resettop();
vm.pushlstring( b );
}
@@ -484,7 +484,7 @@ public class StringLib extends LFunction {
if ( j > len )
j = len;
vm.settop(0);
vm.resettop();
if ( i <= j ) {
LString result = s.substring( i - 1 , j );
vm.pushlstring( result );
@@ -502,7 +502,7 @@ public class StringLib extends LFunction {
*/
static void upper( LuaState vm ) {
String s = vm.tostring(2).toUpperCase();
vm.settop(0);
vm.resettop();
vm.pushstring(s);
}
@@ -521,7 +521,7 @@ public class StringLib extends LFunction {
}
boolean fastMatch = find && ( vm.toboolean( 5 ) || pat.indexOfAny( SPECIALS ) == -1 );
vm.settop(0);
vm.resettop();
if ( fastMatch ) {
int result = s.indexOf( pat, init );

View File

@@ -107,7 +107,7 @@ public class TableLib extends LFunction {
if ( k<j && sep!=null )
sep.write( baos );
}
vm.settop(0);
vm.resettop();
vm.pushlstring( baos.toByteArray() );
} catch (IOException e) {
vm.error(e.getMessage());
@@ -137,7 +137,7 @@ public class TableLib extends LFunction {
*/
case MAXN: {
LTable table = vm.totable(2);
vm.settop(0);
vm.resettop();
vm.pushinteger( table.luaMaxN() );
break;
}
@@ -152,7 +152,7 @@ public class TableLib extends LFunction {
int n = vm.gettop();
LTable table = vm.totable(2);
int pos = (n>=3? vm.tointeger(3): 0);
vm.settop(0);
vm.resettop();
vm.pushlvalue( table.luaRemovePos( pos ) );
break;
}
@@ -170,7 +170,7 @@ public class TableLib extends LFunction {
LTable table = vm.totable(2);
LValue compare = vm.topointer(3);
table.luaSort( vm, compare );
vm.settop(0);
vm.resettop();
break;
}

View File

@@ -304,7 +304,7 @@ public class LTable extends LValue {
// perform a lua call
public boolean luaStackCall(LuaState vm) {
vm.settop(0);
vm.resettop();
int i;
while ( ( i = arrayIndex++ ) < m_vector.length ) {
if ( m_vector[i] != LNil.NIL ) {
@@ -622,7 +622,7 @@ public class LTable extends LValue {
vm.pushlvalue(m_vector[j]);
vm.call(2, 1);
boolean result = vm.toboolean(1);
vm.settop(0);
vm.resettop();
return result;
} else {
return m_vector[j].luaBinCmpUnknown( Lua.OP_LT, m_vector[i] );

View File

@@ -110,7 +110,7 @@ public class LThread extends LValue implements Runnable {
synchronized ( this ) {
if ( status == STATUS_DEAD ) {
vm.settop(0);
vm.resettop();
vm.pushboolean(false);
vm.pushstring("cannot resume dead coroutine");
return;
@@ -132,7 +132,7 @@ public class LThread extends LValue implements Runnable {
thread = new Thread(this);
thread.start();
} else {
threadVm.settop(0);
threadVm.resettop();
vm.xmove(threadVm, nargs);
}
@@ -141,7 +141,7 @@ public class LThread extends LValue implements Runnable {
this.wait();
// copy return values from yielding stack state
vm.settop(0);
vm.resettop();
vm.pushboolean(true);
if ( threadVm.cc >= 0 ) {
threadVm.xmove(vm, threadVm.gettop() - 1);
@@ -152,7 +152,7 @@ public class LThread extends LValue implements Runnable {
} catch ( Throwable t ) {
status = STATUS_DEAD;
vm.settop(0);
vm.resettop();
vm.pushboolean(false);
vm.pushstring("thread: "+t);
this.notify();

View File

@@ -82,7 +82,7 @@ public final class LuajavaLib extends LFunction {
className = vm.tostring(2);
try {
Class clazz = Class.forName(className);
vm.settop(0);
vm.resettop();
vm.pushlvalue( new LInstance( clazz, clazz ) );
} catch (Exception e) {
throw new LuaErrorException(e);
@@ -101,7 +101,7 @@ public final class LuajavaLib extends LFunction {
Object o = con.newInstance( args );
// set the result
vm.settop(0);
vm.resettop();
vm.pushlvalue( new LInstance( o, clazz ) );
} catch (Exception e) {
@@ -164,7 +164,7 @@ public final class LuajavaLib extends LFunction {
Field f = c.getField(s);
Object v = CoerceLuaToJava.coerceArg(val, f.getType());
f.set(m_instance,v);
vm.settop(0);
vm.resettop();
} catch (Exception e) {
throw new LuaErrorException(e);
}
@@ -200,7 +200,7 @@ public final class LuajavaLib extends LFunction {
Object result = meth.invoke( instance, args );
// coerce the result
vm.settop(0);
vm.resettop();
vm.pushlvalue( CoerceJavaToLua.coerce(result) );
return false;
} catch (Exception e) {