diff --git a/src/main/java/dan200/computercraft/api/lua/IArguments.java b/src/main/java/dan200/computercraft/api/lua/IArguments.java index 0557665d6..731b00c45 100644 --- a/src/main/java/dan200/computercraft/api/lua/IArguments.java +++ b/src/main/java/dan200/computercraft/api/lua/IArguments.java @@ -188,8 +188,8 @@ public interface IArguments * * Classes implementing this interface may choose to implement a more optimised version which does not copy the * table, instead returning a wrapper version, making it more efficient. However, the caller must guarantee that - * they do not access off the computer thread (and so should not be used with main-thread functions) or once the - * function call has finished (for instance, in callbacks). + * they do not access the table the computer thread (and so should not be used with main-thread functions) or once + * the initial call has finished (for instance, in a callback to {@link MethodResult#pullEvent}). * * @param index The argument number. * @return The argument's value. @@ -448,7 +448,10 @@ public interface IArguments * This is called when the current function finishes, before any main thread tasks have run. * * Called when the current function returns, and so some values are no longer guaranteed to be safe to access. + * + * @deprecated This method was an internal implementation detail and is no longer used. */ + @Deprecated default void releaseImmediate() { } diff --git a/src/main/java/dan200/computercraft/api/lua/ObjectArguments.java b/src/main/java/dan200/computercraft/api/lua/ObjectArguments.java index 2fa9c8fe8..f6eddbbdb 100644 --- a/src/main/java/dan200/computercraft/api/lua/ObjectArguments.java +++ b/src/main/java/dan200/computercraft/api/lua/ObjectArguments.java @@ -5,12 +5,10 @@ */ package dan200.computercraft.api.lua; -import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.Optional; /** * An implementation of {@link IArguments} which wraps an array of {@link Object}. @@ -19,7 +17,6 @@ public final class ObjectArguments implements IArguments { private static final IArguments EMPTY = new ObjectArguments(); - private boolean released = false; private final List args; @Deprecated @@ -67,34 +64,4 @@ public final class ObjectArguments implements IArguments { return args.toArray(); } - - @Nonnull - @Override - public LuaTable getTableUnsafe( int index ) throws LuaException - { - if( released ) - { - throw new IllegalStateException( "Cannot use getTableUnsafe after IArguments has been released" ); - } - - return IArguments.super.getTableUnsafe( index ); - } - - @Nonnull - @Override - public Optional> optTableUnsafe( int index ) throws LuaException - { - if( released ) - { - throw new IllegalStateException( "Cannot use optTableUnsafe after IArguments has been released" ); - } - - return IArguments.super.optTableUnsafe( index ); - } - - @Override - public void releaseImmediate() - { - released = true; - } } diff --git a/src/main/java/dan200/computercraft/core/lua/BasicFunction.java b/src/main/java/dan200/computercraft/core/lua/BasicFunction.java index ee28bf8d5..b6a12ddec 100644 --- a/src/main/java/dan200/computercraft/core/lua/BasicFunction.java +++ b/src/main/java/dan200/computercraft/core/lua/BasicFunction.java @@ -6,7 +6,6 @@ package dan200.computercraft.core.lua; import dan200.computercraft.ComputerCraft; -import dan200.computercraft.api.lua.IArguments; import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.MethodResult; @@ -41,7 +40,7 @@ class BasicFunction extends VarArgFunction @Override public Varargs invoke( LuaState luaState, Varargs args ) throws LuaError { - IArguments arguments = VarargArguments.of( args ); + VarargArguments arguments = VarargArguments.of( args ); MethodResult results; try { @@ -61,7 +60,7 @@ class BasicFunction extends VarArgFunction } finally { - arguments.releaseImmediate(); + arguments.close(); } if( results.getCallback() != null ) diff --git a/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java b/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java index e3652be3f..f848ebde2 100644 --- a/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java +++ b/src/main/java/dan200/computercraft/core/lua/ResultInterpreterFunction.java @@ -51,7 +51,7 @@ class ResultInterpreterFunction extends ResumableVarArgFunction private void checkValid() { - if( arguments.released ) + if( arguments.closed ) { throw new IllegalStateException( "Cannot use LuaTable after IArguments has been released" ); } diff --git a/src/main/java/dan200/computercraft/core/lua/VarargArguments.java b/src/main/java/dan200/computercraft/core/lua/VarargArguments.java index 73b799aea..a501bad3c 100644 --- a/src/main/java/dan200/computercraft/core/lua/VarargArguments.java +++ b/src/main/java/dan200/computercraft/core/lua/VarargArguments.java @@ -17,9 +17,9 @@ import java.util.Optional; final class VarargArguments implements IArguments { - private static final IArguments EMPTY = new VarargArguments( Constants.NONE ); + private static final VarargArguments EMPTY = new VarargArguments( Constants.NONE ); - boolean released; + boolean closed; private final Varargs varargs; private Object[] cache; @@ -28,7 +28,7 @@ final class VarargArguments implements IArguments this.varargs = varargs; } - static IArguments of( Varargs values ) + static VarargArguments of( Varargs values ) { return values == Constants.NONE ? EMPTY : new VarargArguments( values ); } @@ -109,9 +109,9 @@ final class VarargArguments implements IArguments @Override public dan200.computercraft.api.lua.LuaTable getTableUnsafe( int index ) throws LuaException { - if( released ) + if( closed ) { - throw new IllegalStateException( "Cannot use getTableUnsafe after IArguments has been released" ); + throw new IllegalStateException( "Cannot use getTableUnsafe after IArguments has been closed." ); } LuaValue value = varargs.arg( index + 1 ); @@ -123,9 +123,9 @@ final class VarargArguments implements IArguments @Override public Optional> optTableUnsafe( int index ) throws LuaException { - if( released ) + if( closed ) { - throw new IllegalStateException( "Cannot use optTableUnsafe after IArguments has been released" ); + throw new IllegalStateException( "Cannot use optTableUnsafe after IArguments has been closed." ); } LuaValue value = varargs.arg( index + 1 ); @@ -134,9 +134,8 @@ final class VarargArguments implements IArguments return Optional.of( new TableImpl( this, (LuaTable) value ) ); } - @Override - public void releaseImmediate() + public void close() { - released = true; + closed = true; } }