mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-22 09:27:39 +00:00
Properly scope IArguments to the current function call
This is a horrible commit: It's a breaking change in a pretty subtle way, which means it won't be visible while updating. Fortunately I think the only mod on 1.19.4 is Plethora, but other mods (Mek, Advanced Peripherals) may be impacted when they update. Sorry! For some motivation behind the original issue: The default IArguments implementation (VarargArguments) lazily converts Lua arguments to Java ones. This is mostly important when passing tables to Java functions, as we can avoid the conversion entirely if the function uses IArguments.getTableUnsafe. However, this lazy conversion breaks down if IArguments is accessed on a separate thread, as Lua values are not thread-safe. Thus we need to perform this conversion before the cross-thread sharing occurs. Now, ideally this would be an implementation detail and entirely invisible to the user. One approach here would be to only perform this lazy conversion for methods annotated with @LuaFunction(unsafe=true), and have it be eager otherwise. However, the peripheral API gets in the way here, as it means we can no longer inspect the "actual" method being invoked. And so, alas, this must leak into the public API. TLDR: If you're getting weird errors about scope, add an IArguments.escapes() call before sharing the arguments between threads. Closes #1384
This commit is contained in:
@@ -219,7 +219,7 @@ public class TurtleAPI implements ILuaAPI {
|
||||
* @cc.since 1.4
|
||||
*/
|
||||
@LuaFunction
|
||||
public final MethodResult place(IArguments args) {
|
||||
public final MethodResult place(IArguments args) throws LuaException {
|
||||
return trackCommand(new TurtlePlaceCommand(InteractDirection.FORWARD, args.getAll()));
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class TurtleAPI implements ILuaAPI {
|
||||
* @see #place For more information about placing items.
|
||||
*/
|
||||
@LuaFunction
|
||||
public final MethodResult placeUp(IArguments args) {
|
||||
public final MethodResult placeUp(IArguments args) throws LuaException {
|
||||
return trackCommand(new TurtlePlaceCommand(InteractDirection.UP, args.getAll()));
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ public class TurtleAPI implements ILuaAPI {
|
||||
* @see #place For more information about placing items.
|
||||
*/
|
||||
@LuaFunction
|
||||
public final MethodResult placeDown(IArguments args) {
|
||||
public final MethodResult placeDown(IArguments args) throws LuaException {
|
||||
return trackCommand(new TurtlePlaceCommand(InteractDirection.DOWN, args.getAll()));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user