1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-28 04:17:38 +00:00

Some changes to Lua machines and string loading

- Share the ILuaContext across all method calls, as well as shifting it
   into an anonymous class.
 - Move the load/loadstring prefixing into bios.lua
 - Be less militant in prefixing chunk names:
   - load will no longer do any auto-prefixing.
   - loadstring will not prefix when there no chunk name is supplied.
     Before we would do `"=" .. supplied_program`, which made no sense.
This commit is contained in:
SquidDev
2019-03-10 12:24:55 +00:00
parent 7b5a918941
commit 5b942ff9c1
6 changed files with 216 additions and 202 deletions

View File

@@ -32,7 +32,11 @@ public interface ILuaContext
* intercepted, or the computer will leak memory and end up in a broken state.
*/
@Nonnull
Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException;
default Object[] pullEvent( @Nullable String filter ) throws LuaException, InterruptedException {
Object[] results = pullEventRaw( filter );
if( results.length >= 1 && results[0].equals( "terminate" ) ) throw new LuaException( "Terminated", 0 );
return results;
}
/**
* The same as {@link #pullEvent(String)}, except "terminated" events are ignored. Only use this if you want to
@@ -47,7 +51,9 @@ public interface ILuaContext
* @see #pullEvent(String)
*/
@Nonnull
Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException;
default Object[] pullEventRaw( @Nullable String filter ) throws InterruptedException {
return yield( new Object[] { filter } );
}
/**
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to