1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00

Change timeout system to occur on instructions instead of API calls

This means loops which do not touch CC specific methods will still
produce an error, rather than terminating the computer.
This commit is contained in:
SquidDev 2017-05-01 18:46:28 +01:00
parent 0420b6c831
commit 73873eb8cb

View File

@ -67,6 +67,7 @@ public InputStream findResource( String filename )
state.debug = new DebugHandler( state )
{
private int count = 0;
private boolean hasSoftAbort;
@Override
public void onInstruction( DebugState ds, DebugFrame di, int pc, Varargs extras, int top ) throws LuaError
@ -77,6 +78,10 @@ public void onInstruction( DebugState ds, DebugFrame di, int pc, Varargs extras,
if( m_hardAbortMessage != null ) LuaThread.yield( state, NONE );
this.count = 0;
}
else
{
handleSoftAbort();
}
super.onInstruction( ds, di, pc, extras, top );
}
@ -85,6 +90,24 @@ public void onInstruction( DebugState ds, DebugFrame di, int pc, Varargs extras,
public void poll() throws LuaError
{
if( m_hardAbortMessage != null ) LuaThread.yield( state, NONE );
handleSoftAbort();
}
private void handleSoftAbort() throws LuaError {
// If the soft abort has been cleared then we can reset our flags and continue.
String message = m_softAbortMessage;
if (message == null) {
hasSoftAbort = false;
return;
}
if (hasSoftAbort && m_hardAbortMessage == null) {
// If we have fired our soft abort, but we haven't been hard aborted then everything is OK.
return;
}
hasSoftAbort = true;
throw new LuaError(message);
}
};
@ -269,17 +292,6 @@ public void unload()
}
}
private void tryAbort() throws LuaError
{
String abortMessage = m_softAbortMessage;
if( abortMessage != null )
{
m_softAbortMessage = null;
m_hardAbortMessage = null;
throw new LuaError( abortMessage );
}
}
private LuaTable wrapLuaObject( ILuaObject object )
{
LuaTable table = new LuaTable();
@ -296,7 +308,6 @@ private LuaTable wrapLuaObject( ILuaObject object )
@Override
public Varargs invoke( final LuaState state, Varargs _args ) throws LuaError
{
tryAbort();
Object[] arguments = toObjects( _args, 1 );
Object[] results;
try