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

View File

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

View File

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

View File

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

View File

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

View File

@@ -304,7 +304,7 @@ public class LTable extends LValue {
// perform a lua call // perform a lua call
public boolean luaStackCall(LuaState vm) { public boolean luaStackCall(LuaState vm) {
vm.settop(0); vm.resettop();
int i; int i;
while ( ( i = arrayIndex++ ) < m_vector.length ) { while ( ( i = arrayIndex++ ) < m_vector.length ) {
if ( m_vector[i] != LNil.NIL ) { if ( m_vector[i] != LNil.NIL ) {
@@ -622,7 +622,7 @@ public class LTable extends LValue {
vm.pushlvalue(m_vector[j]); vm.pushlvalue(m_vector[j]);
vm.call(2, 1); vm.call(2, 1);
boolean result = vm.toboolean(1); boolean result = vm.toboolean(1);
vm.settop(0); vm.resettop();
return result; return result;
} else { } else {
return m_vector[j].luaBinCmpUnknown( Lua.OP_LT, m_vector[i] ); 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 ) { synchronized ( this ) {
if ( status == STATUS_DEAD ) { if ( status == STATUS_DEAD ) {
vm.settop(0); vm.resettop();
vm.pushboolean(false); vm.pushboolean(false);
vm.pushstring("cannot resume dead coroutine"); vm.pushstring("cannot resume dead coroutine");
return; return;
@@ -132,7 +132,7 @@ public class LThread extends LValue implements Runnable {
thread = new Thread(this); thread = new Thread(this);
thread.start(); thread.start();
} else { } else {
threadVm.settop(0); threadVm.resettop();
vm.xmove(threadVm, nargs); vm.xmove(threadVm, nargs);
} }
@@ -141,7 +141,7 @@ public class LThread extends LValue implements Runnable {
this.wait(); this.wait();
// copy return values from yielding stack state // copy return values from yielding stack state
vm.settop(0); vm.resettop();
vm.pushboolean(true); vm.pushboolean(true);
if ( threadVm.cc >= 0 ) { if ( threadVm.cc >= 0 ) {
threadVm.xmove(vm, threadVm.gettop() - 1); threadVm.xmove(vm, threadVm.gettop() - 1);
@@ -152,7 +152,7 @@ public class LThread extends LValue implements Runnable {
} catch ( Throwable t ) { } catch ( Throwable t ) {
status = STATUS_DEAD; status = STATUS_DEAD;
vm.settop(0); vm.resettop();
vm.pushboolean(false); vm.pushboolean(false);
vm.pushstring("thread: "+t); vm.pushstring("thread: "+t);
this.notify(); this.notify();

View File

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