diff --git a/README.md b/README.md index ed91e79..6d098f0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# computercraft-haxelib +# cctweaked-haxelib -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. \ No newline at end of file +This is a minimal set of externs for the Lua APIs of CC: Tweaked for the [haxe programming language](https://haxe.org). It's not available through haxelib *yet*. Only Lua is supported as a platform. \ No newline at end of file diff --git a/build.hxml b/build.hxml new file mode 100644 index 0000000..6aff805 --- /dev/null +++ b/build.hxml @@ -0,0 +1 @@ +--lua main.lua \ No newline at end of file diff --git a/haxelib.json b/haxelib.json index a6aa7f6..dfa9bd5 100644 --- a/haxelib.json +++ b/haxelib.json @@ -1,13 +1,11 @@ { - "name": "computercraft", - "url": "https://github.com/apemanzilla/computercraft-haxelib", + "name": "cctweaked", + "url": "https://github.com/CCTweakedHaxePrograms/cctweaked-haxelib", "license": "MIT", - "tags": ["computercraft", "cc", "minecraft", "lua"], - "description": "Bindings for the Lua APIs of the ComputerCraft mod for Minecraft", - "version": "1.0.2", + "tags": ["computercraft", "cc", "minecraft", "lua", "cctweaked"], + "description": "Bindings for the Lua APIs of the CC: Tweaked mod for Minecraft", + "version": "2.0.0", "classPath": "src", - "releasenote": "Fixes missing @:luaDotMethod on TerminalObject and package for ComputerCraft", - "contributors": [ - "apemanzilla" - ] -} \ No newline at end of file + "releasenote": "Adds many missing apis added by CC: Tweaked", + "contributors": ["apemanzilla", "RGFTheCoder"] +} diff --git a/src/cc/Colors.hx b/src/cc/Colors.hx index f5e81ad..870b82d 100644 --- a/src/cc/Colors.hx +++ b/src/cc/Colors.hx @@ -6,24 +6,26 @@ typedef Color = Int; @:native("colors") extern class Colors { - public static function combine(colors: Rest): Color; - public static function subtract(from: Color, colors: Rest): Color; - public static function test(it: Color, check: Color): Bool; + public static function combine(colors:Rest):Color; + public static function subtract(from:Color, colors:Rest):Color; + public static function test(it:Color, check:Color):Bool; - public static var white: Color; - public static var orange: Color; - public static var magenta: Color; - public static var lightBlue: Color; - public static var yellow: Color; - public static var lime: Color; - public static var pink: Color; - public static var gray: Color; - public static var lightGray: Color; - public static var cyan: Color; - public static var purple: Color; - public static var blue: Color; - public static var brown: Color; - public static var green: Color; - public static var red: Color; - public static var black: Color; + public static var white:Color; + public static var orange:Color; + public static var magenta:Color; + public static var lightBlue:Color; + public static var yellow:Color; + 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; + public static var brown:Color; + public static var green:Color; + public static var red:Color; + public static var black:Color; } diff --git a/src/cc/Commands.hx b/src/cc/Commands.hx index dfd525c..b0bb9b5 100644 --- a/src/cc/Commands.hx +++ b/src/cc/Commands.hx @@ -4,29 +4,29 @@ import lua.Table; @:multiReturn extern class CommandExecutionResult { - var successful: Bool; - var output: Table; + var successful:Bool; + var output:Table; } @:multiReturn extern class BlockPosition { - var x: Int; - var y: Int; - var z: Int; + var x:Int; + var y:Int; + var z:Int; } extern class BlockInfo { - var name: String; - var metadata: Int; - var state: Dynamic; + var name:String; + var metadata:Int; + var state:Dynamic; } @:native("commands") extern class Commands { - public static function exec(command: String): CommandExecutionResult; - public static function execAsync(command: String): Int; - public static function list(): Table; - public static function getBlockPosition(): BlockPosition; - 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; -} \ No newline at end of file + public static function exec(command:String):CommandExecutionResult; + public static function execAsync(command:String):Int; + public static function list():Table; + public static function getBlockPosition():BlockPosition; + public static function getBlockInfos(x1:Int, y1:Int, z1:Int, x2:Int, y2:Int, z2:Int):Table; + public static function getBlockInfo(x:Int, y:Int, z:Int):BlockInfo; +} diff --git a/src/cc/ComputerCraft.hx b/src/cc/ComputerCraft.hx index c4793a4..c17f65f 100644 --- a/src/cc/ComputerCraft.hx +++ b/src/cc/ComputerCraft.hx @@ -1,10 +1,15 @@ package cc; +import lua.Table; + @:native("_G") extern class ComputerCraft { - 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; -} \ No newline at end of file + 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, ?completeFn:String->Table, ?default: String + ):String; + public static var _HOST:String; + public static var _CC_DEFAULT_SETTINGS:String; +} diff --git a/src/cc/Disk.hx b/src/cc/Disk.hx index b634f70..1e5b8f3 100644 --- a/src/cc/Disk.hx +++ b/src/cc/Disk.hx @@ -2,15 +2,15 @@ package cc; @:native("disk") extern class Disk { - public static function isPresent(side: String): Bool; - 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; -} \ No newline at end of file + 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 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; +} diff --git a/src/cc/FileSystem.hx b/src/cc/FileSystem.hx index 60e7b0b..7ff4021 100644 --- a/src/cc/FileSystem.hx +++ b/src/cc/FileSystem.hx @@ -7,34 +7,58 @@ 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 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 readLine(?withTrailing:Bool):Null; + public function readAll():Null; + public function read(?count:Int):Null; + public function write(data:String):Void; + public function writeLine(data:String):Void; + public function flush():Void; + public function seek(?whence:String, ?offset:Int):Void; + 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 list(path: String): Table; - 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 find(pattern: String): Table; - public static function getDir(path: String): String; - // todo: complete() -} \ No newline at end of file + 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; + 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 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 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; + public static function getCapacity(path:String):Null; + public static function attributes(path:String):FileAttributes; +} diff --git a/src/cc/GPS.hx b/src/cc/GPS.hx index b96c7f2..b993e01 100644 --- a/src/cc/GPS.hx +++ b/src/cc/GPS.hx @@ -2,12 +2,13 @@ package cc; @:multiReturn extern class GPSLocation { - var x: Float; - var y: Float; - var z: Float; + var x:Float; + var y:Float; + var z:Float; } @:native("gps") extern class GPS { - public static function locate(?timeout: Float, ?debug: Bool): GPSLocation; -} \ No newline at end of file + public static var CHANNEL_GPS:Int; + public static function locate(?timeout:Float, ?debug:Bool):GPSLocation; +} diff --git a/src/cc/HTTP.hx b/src/cc/HTTP.hx index 84fd5af..dcacd07 100644 --- a/src/cc/HTTP.hx +++ b/src/cc/HTTP.hx @@ -1,24 +1,53 @@ -package src.cc; +package cc; import lua.Table; @:multiReturn extern class HTTPCheckReturn { - public var allowed: Bool; - public var error: Null; + public var allowed:Bool; + public var error:Null; } +@: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 getResponseCode():Int; + public function getResponseHeaders():Table; + public function readLine(?withTrailing:Bool):Null; + public function readAll():Null; + public function read(?count:Int):Null; + public function seek(?whence:String, ?offset:Int):Void; + public function close():Void; +} + +@:luaDotMethod +extern class Websocket { + public function recieve(?timeout:Float):Null; + public function send(message:String, ?binary:Float):Void; + public function close():Void; +} + +class Request { + var url:String; + var body:Null; + var headers:Null>; + var binary:Null; + var method:Null; + var redirect:Null; } @:native("http") extern class HTTP { - public static function checkURL(url: String): Bool; - public static function request(url: String, ?postData: String, ?headers: Table): Void; - public static function get(url: String, ?headers: Table): Null; - public static function post(url: String, postData: String, ?header: Table): Null; -} \ No newline at end of file + public static function request(url:String, ?body:String, ?headers:Table, ?binary:Bool):Void; + public static function get(url:String, ?headers:Table, ?binary:Bool):Null; + public static function post(url:String, postData:String, ?header:Table, ?binary:Bool):Null; + public static function checkURLAsync(url:String):Bool; + public static function checkURL(url:String):Bool; + public static function websocket(url:String, ?headers:Table):Websocket; + public static function websocketAsync(url:String, ?headers:Table):Void; +} diff --git a/src/cc/Help.hx b/src/cc/Help.hx index 999ff1a..d19b95f 100644 --- a/src/cc/Help.hx +++ b/src/cc/Help.hx @@ -4,9 +4,9 @@ import lua.Table; @:native("help") extern class Help { - public static function path(): String; - public static function setPath(path: String): Void; - public static function lookup(topic: String): String; - public static function topics(): Table; - public static function completeTopic(prefix: String): Table; -} \ No newline at end of file + public static function path():String; + public static function setPath(path:String):Void; + public static function lookup(topic:String):String; + public static function topics():Table; + public static function completeTopic(prefix:String):Table; +} diff --git a/src/cc/IO.hx b/src/cc/IO.hx new file mode 100644 index 0000000..55e144d --- /dev/null +++ b/src/cc/IO.hx @@ -0,0 +1,40 @@ +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; + 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; + public static function open(filename:String, ?mode:OpenFileMode):LLFileHandle; + public static function output(?file:String):LLFileHandle; + public static function read():Null; + public static function type(obj:Any):Null; + public static function write(text:String):Void; +} diff --git a/src/cc/periphs/Command.hx b/src/cc/periphs/Command.hx new file mode 100644 index 0000000..0e36688 --- /dev/null +++ b/src/cc/periphs/Command.hx @@ -0,0 +1,15 @@ +package cc.periphs; + +@:multiReturn +extern class CommandResult { + var success:Bool; + var failMessage:Null; +} + +extern class Command { + public static function getCommand():String; + + public static function setCommand(command:String):Void; + + public static function runCommand():CommandResult; +} diff --git a/src/cc/periphs/Computer.hx b/src/cc/periphs/Computer.hx new file mode 100644 index 0000000..e41666a --- /dev/null +++ b/src/cc/periphs/Computer.hx @@ -0,0 +1,10 @@ +package cc.periphs; + +extern class Computer { + public static function turnOn():Void; // Turn the other computer on. + public static function shutdown():Void; // Shutdown the other computer. + public static function reboot():Void; // Reboot or turn on the other computer. + public static function getID():Int; // Get the other computer's ID. + public static function isOn():Bool; // Determine if the other computer is on. + public static function getLabel():Null; // Get the other computer's label. +} diff --git a/src/cc/periphs/Disk.hx b/src/cc/periphs/Disk.hx new file mode 100644 index 0000000..5ec992d --- /dev/null +++ b/src/cc/periphs/Disk.hx @@ -0,0 +1,15 @@ +package cc.periphs; + +extern class Disk { + public static function isDiskPresent():Bool; // Returns whether a disk is currently inserted in the drive. + public static function getDiskLabel():Null; // Returns the label of the disk in the drive if available. + public static function setDiskLabel(?label:String):Void; // Sets or clears the label for a disk. + public static function hasData():Bool; // Returns whether a disk with data is inserted. + public static function getMountPath():Null; // Returns the mount path for the inserted disk. + public static function hasAudio():Bool; // Returns whether a disk with audio is inserted. + public static function getAudioTitle():Null; // Returns the title of the inserted audio disk. + public static function playAudio():Void; // Plays the audio in the inserted disk, if available. + public static function stopAudio():Void; // Stops any audio that may be playing. + public static function ejectDisk():Void; // Ejects any disk that may be in the drive. + public static function getDiskID():Int; // Returns the ID of the disk inserted in the drive. +} diff --git a/src/cc/periphs/EnergyStorage.hx b/src/cc/periphs/EnergyStorage.hx new file mode 100644 index 0000000..43c7d3d --- /dev/null +++ b/src/cc/periphs/EnergyStorage.hx @@ -0,0 +1,6 @@ +package cc.periphs; + +extern class EnergyStorage { + public static function getEnergy():Int; // Get the energy of this block. + public static function getEnergyCapacity():Int; // Get the maximum amount of energy this block can store. +} diff --git a/src/cc/periphs/FluidStorage.hx b/src/cc/periphs/FluidStorage.hx new file mode 100644 index 0000000..672d7ea --- /dev/null +++ b/src/cc/periphs/FluidStorage.hx @@ -0,0 +1,9 @@ +package cc.periphs; + +import lua.Table; + +extern class FluidStorage { + public static function tanks():Table>; + public static function pushFluid(toName:String, ?limit:Float, ?fluidName:String):Float; + public static function pullFluid(fromName:String, ?limit:Float, ?fluidName:String):Float; +} diff --git a/src/cc/periphs/ItemStorage.hx b/src/cc/periphs/ItemStorage.hx new file mode 100644 index 0000000..970e6db --- /dev/null +++ b/src/cc/periphs/ItemStorage.hx @@ -0,0 +1,22 @@ +package cc.periphs; + +import lua.Table; + +interface ReducedItemInfo { + public var count:Int; + public var name:String; +} + +interface DetailedItemInfo extends ReducedItemInfo { + public var displayName:String; + public var maxCount:Int; + public var tags:Table; +} + +extern class ItemStorage { + public static function size():Int; // Get the size of this inventory. + public static function list():Table; // List all items in this inventory. + public static function getItemDetail(slot:Int):DetailedItemInfo; // Get detailed information about an item. + public static function pushItems(toName:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int; // Push items from one inventory to another connected one. + public static function pullItems(fromName:String, fromSlot:Int, ?limit:Int, ?toSlot:Int):Int; // Pull items from a connected inventory into this one. +} diff --git a/src/cc/periphs/Modem.hx b/src/cc/periphs/Modem.hx new file mode 100644 index 0000000..a042cf3 --- /dev/null +++ b/src/cc/periphs/Modem.hx @@ -0,0 +1,17 @@ +package cc.periphs; + +import lua.Table; + +extern class Modem { + public static function open(channel:Int):Void; // Open a channel on a modem. + public static function isOpen(channel:Int):Bool; // Check if a channel is open. + public static function close(channel:Int):Void; // Close an open channel, meaning it will no longer receive messages. + public static function closeAll():Void; // Close all open channels. + public static function transmit(channel:Int, replyChannel:Int, payload:Any):Void; // Sends a modem message on a certain channel. + public static function isWireless():Bool; // Determine if this is a wired or wireless modem. + public static function getNamesRemote():Table; // List all remote peripherals on the wired network. + public static function isPresentRemote(name:String):Bool; // Determine if a peripheral is available on this wired network. + public static function getTypeRemote(name:String):String; // Get the type of a peripheral is available on this wired network. + public static function getMethodsRemote(name:String):Table; // Get all available methods for the remote peripheral with the given name. + public static function getNameLocal():String; // Returns the network name of the current computer, if the modem is on. +} diff --git a/src/cc/periphs/Monitor.hx b/src/cc/periphs/Monitor.hx new file mode 100644 index 0000000..44dd2d6 --- /dev/null +++ b/src/cc/periphs/Monitor.hx @@ -0,0 +1,46 @@ +package cc.periphs; + +@: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; +} + +extern class Monitor { + public static function setTextScale(scale:Float):Void; // Set the scale of this monitor. + public static function getTextScale():Float; // Get the monitor's current text scale. + public static function write(text:String):Void; // Write text at the current cursor position, moving the cursor to the end of the text. + public static function scroll(y:Int):Void; // Move all positions up (or down) by y pixels. + public static function getCursorPos():Position; // Get the position of the cursor. + public static function setCursorPos(x:Int, y:Int):Void; // et the position of the cursor. + public static function getCursorBlink():Bool; // Checks if the cursor is currently blinking. + public static function setCursorBlink(blink:Bool):Void; // Sets whether the cursor should be visible (and blinking) at the current cursor position. + public static function getSize():Int; // Get the size of the terminal. + public static function clear():Void; // Clears the terminal, filling it with the current background colour. + public static function clearLine():Void; // Clears the line the cursor is currently on, filling it with the current background colour. + public static function getTextColour():Color; // Return the colour that new text will be written as. + public static function getTextColor():Color; // Return the colour that new text will be written as. + public static function setTextColour(colour:Color):Void; // Set the colour that new text will be written as. + public static function setTextColor(colour:Color):Void; // Set the colour that new text will be written as. + public static function getBackgroundColour():Color; // Return the current background colour. + public static function getBackgroundColor():Color; // Return the current background colour. + public static function setBackgroundColour(colour:Color):Void; // Set the current background colour. + public static function setBackgroundColor(colour:Color):Void; // Set the current background colour. + public static function isColour():Bool; // Determine if this terminal supports colour. + public static function isColor():Bool; // Determine if this terminal supports colour. + public static function blit(text:String, textColour:String, + backgroundColour:String):Void; // Writes text to the terminal with the specific foreground and background characters. + public static function setPaletteColour(index:Color, packedColour:Int):Void; // Set the palette for a specific colour. + public static function setPaletteColor(index:Color, packedColour:Int):Void; // Set the palette for a specific colour. + public static function getPaletteColour(colour:Color):ColorData; // Get the current palette for a specific colour. + public static function getPaletteColor(colour:Color):ColorData; // Get the current palette for a specific colour. +} diff --git a/src/cc/periphs/Printer.hx b/src/cc/periphs/Printer.hx new file mode 100644 index 0000000..97f7746 --- /dev/null +++ b/src/cc/periphs/Printer.hx @@ -0,0 +1,19 @@ +package cc.periphs; + +@:multiReturn +extern class Position { + var x:Int; + var y:Int; +} + +extern class Printer { + public static function write(text:String):Void; // Writes text to the current page. + public static function getCursorPos():Position; // Returns the current position of the cursor on the page. + public static function setCursorPos(x:Int, y:Int):Void; // Sets the position of the cursor on the page. + public static function getPageSize():Position; // Returns the size of the current page. + public static function newPage():Bool; // Starts printing a new page. + public static function endPage():Bool; // Finalizes printing of the current page and outputs it to the tray. + public static function setPageTitle(?title:String):Void; // Sets the title of the current page. + public static function getInkLevel():Float; // Returns the amount of ink left in the printer. + public static function getPaperLevel():Int; // Returns the amount of paper left in the printer. +} diff --git a/src/cc/periphs/Speaker.hx b/src/cc/periphs/Speaker.hx new file mode 100644 index 0000000..7578b99 --- /dev/null +++ b/src/cc/periphs/Speaker.hx @@ -0,0 +1,6 @@ +package cc.periphs; + +extern class Speaker { + public static function playSound(name:String, ?volume:Float, ?pitch:Float):Bool; // Plays a sound through the speaker. + public static function playNote(name:String, ?volume:Float, ?pitch:Float):Bool; // Plays a note block note through the speaker. +}