use of dan200.computercraft.api.lua.MethodResult in project Mekanism by mekanism.
the class CCMethodCaller method callMethod.
// Note: This method intentionally matches the signature for IDynamicLuaObject, but this class doesn't implement it to make sure
// the peripheral doesn't have issues if something is doing an instance check. (There may not be any cases this is a problem)
@Nonnull
public MethodResult callMethod(@Nonnull ILuaContext context, int methodIndex, @Nonnull IArguments arguments) throws LuaException {
if (methodIndex < 0 || methodIndex >= methods.length) {
throw new LuaException(String.format(Locale.ROOT, "Method index '%d' is out of bounds. This %s only has '%d' methods.", methodIndex, getCallerType(), methods.length));
}
BoundComputerMethod method = methods[methodIndex];
CCArgumentWrapper argumentWrapper = new CCArgumentWrapper(arguments);
// Our argument type validator should be thread-safe, so can be run on the ComputerCraft Lua thread
SelectedMethodInfo selectedImplementation = method.findMatchingImplementation(argumentWrapper);
if (selectedImplementation.isThreadSafe()) {
// If our selected implementation is thread-safe, run it directly
return method.run(argumentWrapper, selectedImplementation);
}
// Otherwise, if it is not thread-safe (which will be the majority of our cases), queue it up to run on the game thread
long task = context.issueMainThreadTask(() -> method.run(argumentWrapper, selectedImplementation).getResult());
return new TaskCallback(task).pull;
}
Aggregations