Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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.
- Loading branch information
Showing
with
666 additions
and 260 deletions.
- +16 −4 src/main/java/dan200/computercraft/ComputerCraft.java
- +21 −0 src/main/java/dan200/computercraft/api/ComputerCraftAPI.java
- +38 −0 src/main/java/dan200/computercraft/api/filesystem/IFileSystem.java
- +29 −0 src/main/java/dan200/computercraft/api/lua/IComputerSystem.java
- +47 −0 src/main/java/dan200/computercraft/api/lua/ILuaAPI.java
- +24 −0 src/main/java/dan200/computercraft/api/lua/ILuaAPIFactory.java
- +1 −15 src/main/java/dan200/computercraft/core/apis/BitAPI.java
- +1 −15 src/main/java/dan200/computercraft/core/apis/BufferAPI.java
- +155 −0 src/main/java/dan200/computercraft/core/apis/ComputerAccess.java
- +1 −5 src/main/java/dan200/computercraft/core/apis/FSAPI.java
- +2 −6 src/main/java/dan200/computercraft/core/apis/HTTPAPI.java
- +0 −17 src/main/java/dan200/computercraft/core/apis/ILuaAPI.java
- +2 −1 src/main/java/dan200/computercraft/core/apis/OSAPI.java
- +28 −113 src/main/java/dan200/computercraft/core/apis/PeripheralAPI.java
- +1 −15 src/main/java/dan200/computercraft/core/apis/RedstoneAPI.java
- +1 −15 src/main/java/dan200/computercraft/core/apis/TermAPI.java
- +101 −3 src/main/java/dan200/computercraft/core/computer/Computer.java
- +7 −0 src/main/java/dan200/computercraft/core/filesystem/FileSystem.java
- +185 −0 src/main/java/dan200/computercraft/core/filesystem/FileSystemMount.java
- +1 −1 src/main/java/dan200/computercraft/core/lua/ILuaMachine.java
- +1 −1 src/main/java/dan200/computercraft/core/lua/LuaJLuaMachine.java
- +1 −16 src/main/java/dan200/computercraft/shared/computer/apis/CommandAPI.java
- +1 −1 src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java
- +1 −16 src/main/java/dan200/computercraft/shared/pocket/apis/PocketAPI.java
- +1 −16 src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java
@@ -0,0 +1,38 @@ | ||
package dan200.computercraft.api.filesystem; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Provides a mount of the entire computer's file system. | ||
* | ||
* This exists for use by various APIs - one should not attempt to mount it. | ||
*/ | ||
public interface IFileSystem extends IWritableMount | ||
{ | ||
/** | ||
* Combine two paths together, reducing them into a normalised form. | ||
* | ||
* @param path The main path. | ||
* @param child The path to append. | ||
* @return The combined, normalised path. | ||
*/ | ||
String combine( String path, String child ); | ||
|
||
/** | ||
* Copy files from one location to another. | ||
* | ||
* @param from The location to copy from. | ||
* @param to The location to copy to. This should not exist. | ||
* @throws IOException If the copy failed. | ||
*/ | ||
void copy( String from, String to ) throws IOException; | ||
|
||
/** | ||
* Move files from one location to another. | ||
* | ||
* @param from The location to move from. | ||
* @param to The location to move to. This should not exist. | ||
* @throws IOException If the move failed. | ||
*/ | ||
void move( String from, String to ) throws IOException; | ||
} |
@@ -0,0 +1,29 @@ | ||
package dan200.computercraft.api.lua; | ||
|
||
import dan200.computercraft.api.filesystem.IFileSystem; | ||
import dan200.computercraft.api.peripheral.IComputerAccess; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* An interface passed to {@link ILuaAPIFactory} in order to provide additional information | ||
* about a computer. | ||
*/ | ||
public interface IComputerSystem extends IComputerAccess | ||
{ | ||
/** | ||
* Get the file system for this computer. | ||
* | ||
* @return The computer's file system, or {@code null} if it is not initialised. | ||
*/ | ||
@Nullable | ||
IFileSystem getFileSystem(); | ||
|
||
/** | ||
* Get the label for this computer | ||
* | ||
* @return This computer's label, or {@code null} if it is not set. | ||
*/ | ||
@Nullable | ||
String getLabel(); | ||
} |
@@ -0,0 +1,47 @@ | ||
/* | ||
* This file is part of ComputerCraft - http://www.computercraft.info | ||
* Copyright Daniel Ratcliffe, 2011-2016. Do not distribute without permission. | ||
* Send enquiries to dratcliffe@gmail.com | ||
*/ | ||
|
||
package dan200.computercraft.api.lua; | ||
|
||
import dan200.computercraft.api.ComputerCraftAPI; | ||
|
||
/** | ||
* Represents a {@link ILuaObject} which is stored as a global variable on computer startup. | ||
* | ||
* Before implementing this interface, consider alternative methods of providing methods. It is generally preferred | ||
* to use peripherals to provide functionality to users. | ||
* | ||
* @see ILuaAPIFactory | ||
* @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory) | ||
*/ | ||
public interface ILuaAPI extends ILuaObject | ||
{ | ||
/** | ||
* Get the globals this API will be assigned to. This will override any other global, so you should | ||
* | ||
* @return A list of globals this API will be assigned to. | ||
*/ | ||
String[] getNames(); | ||
|
||
/** | ||
* Called when the computer is turned on. | ||
* | ||
* One should only interact with the file system. | ||
*/ | ||
default void startup() { } | ||
|
||
/** | ||
* Called every time the computer is ticked. This can be used to process various. | ||
*/ | ||
default void update() { } | ||
|
||
/** | ||
* Called when the computer is turned off or unloaded. | ||
* | ||
* This should reset the state of the object, disposing any remaining file handles, or other resources. | ||
*/ | ||
default void shutdown() { } | ||
} |
@@ -0,0 +1,24 @@ | ||
package dan200.computercraft.api.lua; | ||
|
||
import dan200.computercraft.api.ComputerCraftAPI; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Construct an {@link ILuaAPI} for a specific computer. | ||
* | ||
* @see ILuaAPI | ||
* @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory) | ||
*/ | ||
public interface ILuaAPIFactory | ||
{ | ||
/** | ||
* Create a new API instance for a given computer. | ||
* | ||
* @param computer The computer this API is for. | ||
* @return The created API, or {@code null} if one should not be injected. | ||
*/ | ||
@Nullable | ||
ILuaAPI create( @Nonnull IComputerSystem computer ); | ||
} |
Oops, something went wrong.