-
Notifications
You must be signed in to change notification settings - Fork 193
Provide an API for registering custom APIs #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| } | ||
| } | ||
|
|
||
| public static void registerAPIFactory( ILuaAPIFactory provider ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should return a boolean specifying whether the API was actually registered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only really doing it this way because that's what all the other methods do. The only way it could thrown an exception is if the reflection fails, which shouldn't ever happen anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I was referring to if( provider != null && !apiFactories.contains( provider ) ) failing.
| private static List<IMediaProvider> mediaProviders = new ArrayList<>(); | ||
| private static List<ITurtlePermissionProvider> permissionProviders = new ArrayList<>(); | ||
| private static final Map<String, IPocketUpgrade> pocketUpgrades = new HashMap<>(); | ||
| private static final List<ILuaAPIFactory> apiFactories = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using a Set you can avoid explicitly checking if it's been registered later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an argument that this allows for some level of priority ordering. I'm not entirely sure whether such an ordering is needed though - ideally mods shouldn't be overwriting each other's APIs, but it's something worth discussing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any particular reason order is important, but if it is, LinkedHashSet maintains order
ILuaAPI has been moved to dan200.computercraft.api.lua. One creates a new API by registering an instance of ILuaAPIFactory. This takes an instance of IComputerSystem and returns such an API. IComputerSystem is an extension of IComputerAccess, with methods to access additional information about the the computer, such as its label and filesystem.
a30b207 to
5584746
Compare
|
Can one of the admins verify this patch? |
…api-api Provide an API for registering custom APIs
ILuaAPIhas been moved todan200.computercraft.api.lua. One creates a new API by registering an instance ofILuaAPIFactory. This takes an instance ofIComputerSystemand returns such an API.IComputerSystemis an extension ofIComputerAccess, with methods to access additional information about the the computer, such as its label and filesystem.This closes #346, which also explains some of the rational behind this functionality.