Compare commits

..

No commits in common. "master" and "1.0.1" have entirely different histories.

38 changed files with 449 additions and 747 deletions

View File

@ -1,3 +1,3 @@
# cctweaked-haxelib
# computercraft-haxelib
This is a minimal set of externs for the Lua APIs of CC: Tweaked for the [haxe programming language](https://haxe.org). It's available through haxelib as `cctweaked`. Only Lua is supported as a platform.
This is a minimal set of externs for the Lua APIs of ComputerCraft for the [haxe programming language](https://haxe.org). It's available through haxelib as `computercraft`. Only Lua is supported as a platform.

View File

@ -1,2 +0,0 @@
--lua main.lua
--class-path src

View File

@ -1,11 +1,13 @@
{
"name": "cctweaked",
"url": "https://github.com/CCTweakedHaxePrograms/cctweaked-haxelib",
"name": "computercraft",
"url": "https://github.com/apemanzilla/computercraft-haxelib",
"license": "MIT",
"tags": ["computercraft", "cc", "minecraft", "lua", "cctweaked"],
"description": "Bindings for the Lua APIs of the CC: Tweaked mod for Minecraft",
"version": "2.2.0",
"tags": ["computercraft", "cc", "minecraft", "lua"],
"description": "Bindings for the Lua APIs of the ComputerCraft mod for Minecraft",
"version": "1.0.1",
"classPath": "src",
"releasenote": "Adds many missing apis added by CC: Tweaked",
"contributors": ["RGFTheCoder", "apemanzilla"]
"releasenote": "Adds missing HTTP api and globals (in ComputerCraft class)",
"contributors": [
"apemanzilla"
]
}

View File

@ -18,9 +18,7 @@ extern class Colors {
public static var lime: Color;
public static var pink: Color;
public static var gray: Color;
public static var grey:Color;
public static var lightGray: Color;
public static var lightGrey:Color;
public static var cyan: Color;
public static var purple: Color;
public static var blue: Color;

View File

@ -27,6 +27,6 @@ extern class Commands {
public static function execAsync(command: String): Int;
public static function list(): Table<Int, String>;
public static function getBlockPosition(): BlockPosition;
public static function getBlockInfos(x1:Int, y1:Int, z1:Int, x2:Int, y2:Int, z2:Int):Table<Int, BlockInfo>;
public static function getBlockInfo(x: Int, y: Int, z: Int): BlockInfo;
public static function getBlockInfos(x1: Int, y1: Int, z1: Int, x2: Int, y2: Int, z2: Int): Table<Int, BlockInfo>;
}

View File

@ -1,14 +1,10 @@
package cc;
import lua.Table;
package src.cc;
@:native("_G")
extern class ComputerCraft {
public static function sleep(time:Float):Void; // Time is seconds ceil'd to the closest 0.05 or 1/20th
public static function write(text:String):Void;
public static function print(text:String):Void;
public static function printError(message:String):Void;
public static function read(?replaceChar:String, ?history:Table<Int, String>, ?completeFn:String->Table<Int, String>, ?defaultValue:String):String;
public static var _HOST:String;
public static var _CC_DEFAULT_SETTINGS: String;
public static function printError(message: String): Void;
public static function sleep(seconds: Float): Void;
public static function read(?replacement: String): String; // todo: second and third args
public static var _HOST: String;
}

View File

@ -3,14 +3,14 @@ package cc;
@:native("disk")
extern class Disk {
public static function isPresent(side: String): Bool;
public static function getLabel(side:String):String;
public static function setLabel(side:String, label:String):Void;
public static function hasData(side: String): Bool;
public static function getMountPath(side: String): String;
public static function setLabel(side: String, label: String): Void;
public static function getLabel(side: String): String;
public static function getID(side: String): Int;
public static function hasAudio(side: String): Bool;
public static function getAudioTitle(side: String): String;
public static function playAudio(side: String): Void;
public static function stopAudio(side: String): Void;
public static function eject(side: String): Void;
public static function getID(side:String):Int;
}

View File

@ -2,65 +2,39 @@ package cc;
import lua.Table;
enum abstract OpenFileMode(String) {
@:enum
abstract OpenFileMode(String) {
var Read = "r";
var Write = "w";
var Append = "a";
var BinaryRead = "rb";
var BinaryWrite = "wb";
var BinaryAppend = "ab";
}
@:luaDotMethod
extern class FileHandle {
public function readLine(?withTrailing:Bool):Null<String>;
public function readAll():Null<String>;
/**
Returns Int or if `count` is given it returns a string.
**/
public function read(?count:Int):Null<Dynamic>; // TODO: better type
public function close(): Void;
public function readLine(): String;
public function readAll(): String;
public function write(data: String): Void;
public function writeLine(data: String): Void;
public function flush(): Void;
public function seek(?whence:String, ?offset:Int):Int;
public function close():Void;
}
extern class FileAttributes {
var size:Int;
var isDir:Bool;
var isReadOnly:Bool;
var created:Int;
var modified:Int;
}
@:lua
@:native("fs")
extern class FileSystem {
public static function isDriveRoot(path:String):Bool;
public static function complete(path:String, location:String, ?include_files:Bool, ?include_dirs:Bool):Bool;
public static function list(path: String): Table<Int, String>;
public static function combine(base:String, part:String):String;
public static function getName(path:String):String;
public static function getDir(path:String):String;
public static function getSize(path:String):Int;
public static function exists(path: String): Bool;
public static function isDir(path: String): Bool;
public static function isReadOnly(path: String): Bool;
public static function getDrive(path: String): String;
public static function getSize(path: String): Int;
public static function getFreeSpace(path: String): Int;
public static function makeDir(path: String): Void;
public static function move(from: String, to: String): Void;
public static function copy(from: String, to: String): Void;
public static function delete(path: String): Void;
public static function combine(base: String, part: String): String;
public static function open(path: String, mode: OpenFileMode): FileHandle;
// public static function open(path:String, mode:"r"):ReadFileHandle;
// public static function open(path:String, mode:"w"):WriteFileHandle;
// public static function open(path:String, mode:"a"):WriteFileHandle;
// public static function open(path:String, mode:"rb"):BinaryReadFileHandle;
// public static function open(path:String, mode:"wb"):BinaryWriteFileHandle;
// public static function open(path:String, mode:"ab"):BinaryWriteFileHandle;
public static function getDrive(path:String):String;
public static function getFreeSpace(path:String):Int;
public static function find(pattern: String): Table<Int, String>;
public static function getCapacity(path:String):Null<Int>;
public static function attributes(path:String):FileAttributes;
public static function getDir(path: String): String;
// todo: complete()
}

View File

@ -9,6 +9,5 @@ extern class GPSLocation {
@:native("gps")
extern class GPS {
public static var CHANNEL_GPS:Int;
public static function locate(?timeout: Float, ?debug: Bool): GPSLocation;
}

View File

@ -1,4 +1,4 @@
package cc;
package src.cc;
import lua.Table;
@ -8,46 +8,17 @@ extern class HTTPCheckReturn {
public var error: Null<String>;
}
@:multiReturn
extern class SocketMessageReturn {
public var message:String;
public var binary:Bool;
}
@:luaDotMethod
extern class HTTPResponse {
public function close(): Void;
public function readLine(): String;
public function readAll(): String;
public function getResponseCode(): Int;
public function getResponseHeaders():Table<String, String>;
public function readLine(?withTrailing:Bool):Null<String>;
public function readAll():Null<String>;
public function read(?count:Int):Null<String>;
public function seek(?whence:String, ?offset:Int):Void;
public function close():Void;
}
@:luaDotMethod
extern class Websocket {
public function recieve(?timeout:Float):Null<SocketMessageReturn>;
public function send(message:String, ?binary:Float):Void;
public function close():Void;
}
class Request {
var url:String;
var body:Null<String>;
var headers:Null<Table<String, String>>;
var binary:Null<Bool>;
var method:Null<String>;
var redirect:Null<Bool>;
}
@:native("http")
extern class HTTP {
public static function request(url:String, ?body:String, ?headers:Table<String, String>, ?binary:Bool):Void;
public static function get(url:String, ?headers:Table<String, String>, ?binary:Bool):Null<HTTPResponse>;
public static function post(url:String, postData:String, ?header:Table<String, String>, ?binary:Bool):Null<HTTPResponse>;
public static function checkURLAsync(url:String):Bool;
public static function checkURL(url: String): Bool;
public static function websocket(url:String, ?headers:Table<String, String>):Websocket;
public static function websocketAsync(url:String, ?headers:Table<String, String>):Void;
public static function request(url: String, ?postData: String, ?headers: Table<String, String>): Void;
public static function get(url: String, ?headers: Table<String, String>): Null<HTTPResponse>;
public static function post(url: String, postData: String, ?header: Table<String, String>): Null<HTTPResponse>;
}

View File

@ -1,40 +0,0 @@
package cc;
import lua.HaxeIterator;
@:enum
abstract OpenFileMode(String) {
var Read = "r";
var Write = "w";
var Append = "a";
var BinaryRead = "rb";
var BinaryWrite = "wb";
var BinaryAppend = "ab";
}
@:enum
abstract FileType(String) {
var File = "file";
var ClosedFile = "closed file";
}
extern class LLFileHandle {
public static function close():Null<Bool>;
public static function flush():Void;
}
@:native("io")
extern class IO {
public static var stdin:LLFileHandle;
public static var stdout:LLFileHandle;
public static var stderr:LLFileHandle;
public static function close(?file:LLFileHandle):Void;
public static function flush():Void;
public static function input(?file:String):LLFileHandle;
public static function lines(?file:String):HaxeIterator<String>;
public static function open(filename:String, ?mode:OpenFileMode):LLFileHandle;
public static function output(?file:String):LLFileHandle;
public static function read():Null<String>;
public static function type(obj:Any):Null<FileType>;
public static function write(text:String):Void;
}

View File

@ -15,7 +15,7 @@ extern class OS {
public static function unloadAPI(path: String): Void;
public static function queueEvent(type: String, data: Rest<Dynamic>): Void;
public static function clock(): Float;
public static function startTimer(timeout:Float):Int;
public static function startTimer(timeout: Int): Int;
public static function cancelTimer(id: Int): Void;
public static function time(): Float;
public static function sleep(timeout: Float): Void;
@ -24,17 +24,15 @@ extern class OS {
public static function cancelAlarm(id: Int): Void;
public static function shutdown(): Void;
public static function reboot(): Void;
public static function date(?format:String,?time:Int):Dynamic;
public static function epoch(?args:String):Int;
@:native("pullEvent") private static function _pullEvent(?type: String): Dynamic;
@:native("pullEventRaw") private static function _pullEventRaw(?type: String): Dynamic;
public static inline function pullEvent(?type:String):Table<Int, Dynamic> {
public static inline function pullEvent(?type: String): ArrayAccess<Dynamic> {
return cast TableTools.pack(_pullEvent(type));
}
public static inline function pullEventRaw(?type:String):Table<Int, Dynamic> {
public static inline function pullEventRaw(?type: String): ArrayAccess<Dynamic> {
return cast TableTools.pack(_pullEventRaw(type));
}
}

View File

@ -1,22 +1,16 @@
package cc;
import lua.TableTools;
import lua.Table;
import haxe.Constraints;
import haxe.extern.Rest;
@:native("peripheral")
extern class Peripheral {
public static function isPresent(name: String): Bool;
public static function getMethods(name:String):Table<Int,String>;
public static function getType(name: String): String;
public static function getMethods(name: String): Table<String, Function>;
public static function call<T>(name: String, method: String, args: Rest<Dynamic>): T;
public static function wrap<T>(name: String): T;
public static function find<T>(type: String, ?filter: (String, T) -> Bool): Table<Int, T>;
public static function getNames(): Table<Int, String>;
@:native("getType") private static function _getType(name:String): Dynamic;
public static inline function getType(name:String): Table<Int,String>{
return cast TableTools.pack(_getType(name));
}
}

View File

@ -1,13 +0,0 @@
package cc;
@:multiReturn
extern class PocketActionResult {
public var successful:Bool;
public var error:String;
}
@:native("pocket")
extern class Pocket {
public static function equipBack(): PocketActionResult;
public static function unequipBack(): PocketActionResult;
}

View File

@ -14,7 +14,6 @@ extern class TerminalSize {
public var height: Int;
}
@:luaDotMethod
extern class TerminalObject {
public function write(text: String): Void;
public function blit(text: String, colors: String, background: String): Void;

View File

@ -16,7 +16,7 @@ extern class TurtleItemDetail {
extern class TurtleBlockDetail {
public var name: String;
public var tags:lua.Table<String, Bool>;
public var metadata: Int;
public var state: Dynamic;
}

View File

@ -1,15 +0,0 @@
package cc.periphs;
@:multiReturn
extern class CommandResult {
var success:Bool;
var failMessage:Null<String>;
}
extern class Command {
public function getCommand():String;
public function setCommand(command:String):Void;
public function runCommand():CommandResult;
}

View File

@ -1,10 +0,0 @@
package cc.periphs;
extern class Computer {
public function turnOn():Void; // Turn the other computer on.
public function shutdown():Void; // Shutdown the other computer.
public function reboot():Void; // Reboot or turn on the other computer.
public function getID():Int; // Get the other computer's ID.
public function isOn():Bool; // Determine if the other computer is on.
public function getLabel():Null<String>; // Get the other computer's label.
}

View File

@ -1,15 +0,0 @@
package cc.periphs;
extern class Disk {
public function isDiskPresent():Bool; // Returns whether a disk is currently inserted in the drive.
public function getDiskLabel():Null<String>; // Returns the label of the disk in the drive if available.
public function setDiskLabel(?label:String):Void; // Sets or clears the label for a disk.
public function hasData():Bool; // Returns whether a disk with data is inserted.
public function getMountPath():Null<String>; // Returns the mount path for the inserted disk.
public function hasAudio():Bool; // Returns whether a disk with audio is inserted.
public function getAudioTitle():Null<String>; // Returns the title of the inserted audio disk.
public function playAudio():Void; // Plays the audio in the inserted disk, if available.
public function stopAudio():Void; // Stops any audio that may be playing.
public function ejectDisk():Void; // Ejects any disk that may be in the drive.
public function getDiskID():Int; // Returns the ID of the disk inserted in the drive.
}

View File

@ -1,6 +0,0 @@
package cc.periphs;
extern class EnergyStorage {
public function getEnergy():Int; // Get the energy of this block.
public function getEnergyCapacity():Int; // Get the maximum amount of energy this block can store.
}

View File

@ -1,9 +0,0 @@
package cc.periphs;
import lua.Table;
extern class FluidStorage {
public function tanks():Table<Int, Table<String, Any>>;
public function pushFluid(toName:String, ?limit:Float, ?fluidName:String):Float;
public function pullFluid(fromName:String, ?limit:Float, ?fluidName:String):Float;
}

View File

@ -1,29 +0,0 @@
package cc.periphs;
import lua.Table;
interface ReducedItemInfo {
public var count:Int;
public var name:String;
public var nbt:Null<String>;
}
interface DetailedItemInfo extends ReducedItemInfo {
public var displayName:String;
public var tag:Null<String>;
public var maxCount:Int;
public var tags:Table<String, Bool>;
public var durability:Null<Float>;
public var damage:Null<Int>;
public var maxDamage:Null<Int>;
public var enchantments:Null<Array<{displayName:String, level:Int, name:String}>>;
}
extern class ItemStorage {
public function size():Int; // Get the size of this inventory.
public function list():Table<Int, ReducedItemInfo>; // List all items in this inventory.
public function getItemDetail(slot:Int):DetailedItemInfo; // Get detailed information about an item.
public function pushItems(toName:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int; // Push items from one inventory to another connected one.
public function pullItems(fromName:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int; // Pull items from a connected inventory into this one.
public function getItemLimit(slot:Int):Int; // Get the maximum number of items which can be stored in this slot.
}

View File

@ -1,17 +0,0 @@
package cc.periphs;
import lua.Table;
@:luaDotMethod extern class Modem {
public function open(channel:Int):Void; // Open a channel on a modem.
public function isOpen(channel:Int):Bool; // Check if a channel is open.
public function close(channel:Int):Void; // Close an open channel, meaning it will no longer receive messages.
public function closeAll():Void; // Close all open channels.
public function transmit(channel:Int, replyChannel:Int, payload:Any):Void; // Sends a modem message on a certain channel.
public function isWireless():Bool; // Determine if this is a wired or wireless modem.
public function getNamesRemote():Table<Int, String>; // List all remote peripherals on the wired network.
public function isPresentRemote(name:String):Bool; // Determine if a peripheral is available on this wired network.
public function getTypeRemote(name:String):String; // Get the type of a peripheral is available on this wired network.
public function getMethodsRemote(name:String):Table<Int, String>; // Get all available methods for the remote peripheral with the given name.
public function getNameLocal():String; // Returns the network name of the current computer, if the modem is on.
}

View File

@ -1,48 +0,0 @@
package cc.periphs;
import cc.Term.TerminalSize;
@:multiReturn
extern class Position {
var x:Int;
var y:Int;
}
typedef Color = Int;
@:multiReturn
extern class ColorData {
var r:Float;
var g:Float;
var b:Float;
}
@:luaDotMethod extern class Monitor {
public function setTextScale(scale:Float):Void; // Set the scale of this monitor.
public function getTextScale():Float; // Get the monitor's current text scale.
public function write(text:String):Void; // Write text at the current cursor position, moving the cursor to the end of the text.
public function scroll(y:Int):Void; // Move all positions up (or down) by y pixels.
public function getCursorPos():Position; // Get the position of the cursor.
public function setCursorPos(x:Int, y:Int):Void; // et the position of the cursor.
public function getCursorBlink():Bool; // Checks if the cursor is currently blinking.
public function setCursorBlink(blink:Bool):Void; // Sets whether the cursor should be visible (and blinking) at the current cursor position.
public function getSize():TerminalSize; // Get the size of the terminal.
public function clear():Void; // Clears the terminal, filling it with the current background colour.
public function clearLine():Void; // Clears the line the cursor is currently on, filling it with the current background colour.
public function getTextColour():Color; // Return the colour that new text will be written as.
public function getTextColor():Color; // Return the colour that new text will be written as.
public function setTextColour(colour:Color):Void; // Set the colour that new text will be written as.
public function setTextColor(colour:Color):Void; // Set the colour that new text will be written as.
public function getBackgroundColour():Color; // Return the current background colour.
public function getBackgroundColor():Color; // Return the current background colour.
public function setBackgroundColour(colour:Color):Void; // Set the current background colour.
public function setBackgroundColor(colour:Color):Void; // Set the current background colour.
public function isColour():Bool; // Determine if this terminal supports colour.
public function isColor():Bool; // Determine if this terminal supports colour.
public function blit(text:String, textColour:String,
backgroundColour:String):Void; // Writes text to the terminal with the specific foreground and background characters.
public function setPaletteColour(index:Color, packedColour:Int):Void; // Set the palette for a specific colour.
public function setPaletteColor(index:Color, packedColour:Int):Void; // Set the palette for a specific colour.
public function getPaletteColour(colour:Color):ColorData; // Get the current palette for a specific colour.
public function getPaletteColor(colour:Color):ColorData; // Get the current palette for a specific colour.
}

View File

@ -1,19 +0,0 @@
package cc.periphs;
@:multiReturn
extern class PagePosition {
var x:Int;
var y:Int;
}
extern class Printer {
public function write(text:String):Void; // Writes text to the current page.
public function getCursorPos():PagePosition; // Returns the current position of the cursor on the page.
public function setCursorPos(x:Int, y:Int):Void; // Sets the position of the cursor on the page.
public function getPageSize():PagePosition; // Returns the size of the current page.
public function newPage():Bool; // Starts printing a new page.
public function endPage():Bool; // Finalizes printing of the current page and outputs it to the tray.
public function setPageTitle(?title:String):Void; // Sets the title of the current page.
public function getInkLevel():Float; // Returns the amount of ink left in the printer.
public function getPaperLevel():Int; // Returns the amount of paper left in the printer.
}

View File

@ -1,6 +0,0 @@
package cc.periphs;
extern class Speaker {
public function playSound(name:String, ?volume:Float, ?pitch:Float):Bool; // Plays a sound through the speaker.
public function playNote(name:String, ?volume:Float, ?pitch:Float):Bool; // Plays a note block note through the speaker.
}