Skip to content
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

Provide an API for registering custom APIs #491

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@SquidDev
Copy link
Contributor

SquidDev commented Nov 18, 2017

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.

This closes #346, which also explains some of the rational behind this functionality.

@@ -644,6 +646,14 @@ public static void registerMediaProvider( IMediaProvider provider )
}
}

public static void registerAPIFactory( ILuaAPIFactory provider )

This comment has been minimized.

@Lignum

Lignum Nov 18, 2017

Contributor

Perhaps this should return a boolean specifying whether the API was actually registered?

This comment has been minimized.

@SquidDev

SquidDev Nov 18, 2017

Author Contributor

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.

This comment has been minimized.

@Lignum

Lignum Nov 18, 2017

Contributor

Oh, I was referring to if( provider != null && !apiFactories.contains( provider ) ) failing.

@@ -244,6 +245,7 @@
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<>();

This comment has been minimized.

@dmarcuse

dmarcuse Nov 18, 2017

Contributor

By using a Set you can avoid explicitly checking if it's been registered later

This comment has been minimized.

@SquidDev

SquidDev Nov 18, 2017

Author Contributor

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.

This comment has been minimized.

@dmarcuse

dmarcuse Nov 18, 2017

Contributor

I don't think there's any particular reason order is important, but if it is, LinkedHashSet maintains order

Provide an API for registering custom APIs
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.

@SquidDev SquidDev force-pushed the SquidDev-CC:feature/api-api branch from a30b207 to 5584746 Nov 19, 2017

@thatcraniumguy

This comment has been minimized.

Copy link

thatcraniumguy commented May 23, 2018

Can one of the admins verify this patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.