Initial commit

This commit is contained in:
apemanzilla 2018-03-21 23:16:51 -04:00
commit c3ee593f86
26 changed files with 673 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.zip
.vscode/*

21
LICENSE.txt Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Dominic "apemanzilla" Marcuse
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# computercraft-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.

0
extraParams.hxml Normal file
View File

13
haxelib.json Normal file
View File

@ -0,0 +1,13 @@
{
"name": "computercraft",
"url": "https://github.com/apemanzilla/computercraft-haxelib",
"license": "MIT",
"tags": ["computercraft", "cc", "minecraft", "lua"],
"description": "Bindings for the Lua APIs of the ComputerCraft mod for Minecraft",
"version": "1.0.0",
"classPath": "src",
"releasenote": "Initial release",
"contributors": [
"apemanzilla"
]
}

29
src/cc/Colors.hx Normal file
View File

@ -0,0 +1,29 @@
package cc;
import haxe.extern.Rest;
typedef Color = Int;
@:native("colors")
extern class Colors {
public static function combine(colors: Rest<Color>): Color;
public static function subtract(from: Color, colors: Rest<Color>): 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;
}

32
src/cc/Commands.hx Normal file
View File

@ -0,0 +1,32 @@
package cc;
import lua.Table;
@:multiReturn
extern class CommandExecutionResult {
var successful: Bool;
var output: Table<Int, String>;
}
@:multiReturn
extern class BlockPosition {
var x: Int;
var y: Int;
var z: Int;
}
extern class BlockInfo {
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<Int, String>;
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<Int, BlockInfo>;
}

16
src/cc/Disk.hx Normal file
View File

@ -0,0 +1,16 @@
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;
}

40
src/cc/FileSystem.hx Normal file
View File

@ -0,0 +1,40 @@
package cc;
import lua.Table;
@:enum
abstract OpenFileMode(String) {
var Read = "r";
var Write = "w";
var Append = "a";
}
@: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;
}
@:native("fs")
extern class FileSystem {
public static function list(path: String): Table<Int, String>;
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<Int, String>;
public static function getDir(path: String): String;
// todo: complete()
}

13
src/cc/GPS.hx Normal file
View File

@ -0,0 +1,13 @@
package cc;
@:multiReturn
extern class GPSLocation {
var x: Float;
var y: Float;
var z: Float;
}
@:native("gps")
extern class GPS {
public static function locate(?timeout: Float, ?debug: Bool): GPSLocation;
}

12
src/cc/Help.hx Normal file
View File

@ -0,0 +1,12 @@
package cc;
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<Int, String>;
public static function completeTopic(prefix: String): Table<Int, String>;
}

127
src/cc/Keys.hx Normal file
View File

@ -0,0 +1,127 @@
package cc;
@:native("keys")
extern class Keys {
public static function getName(code: Int): String;
public static inline function getCode(name: String): Int {
// i know this is bad please don't judge me
return (cast Keys)[cast name];
}
public static var a: Int;
public static var c: Int;
public static var b: Int;
public static var e: Int;
public static var pageUp: Int;
public static var g: Int;
public static var f: Int;
public static var i: Int;
public static var h: Int;
public static var k: Int;
public static var j: Int;
public static var space: Int;
public static var l: Int;
public static var o: Int;
public static var n: Int;
public static var q: Int;
public static var f1: Int;
public static var s: Int;
// public static var return: Int;
public static var f5: Int;
public static var seven: Int;
public static var w: Int;
public static var numPadEnter: Int;
public static var y: Int;
public static var x: Int;
public static var numPad6: Int;
public static var z: Int;
public static var backslash: Int;
public static var rightBracket: Int;
public static var f9: Int;
public static var yen: Int;
public static var left: Int;
public static var numPadSubtract: Int;
public static var noconvert: Int;
public static var leftCtrl: Int;
public static var rightCtrl: Int;
public static var numPad2: Int;
public static var insert: Int;
public static var delete: Int;
public static var f4: Int;
public static var grave: Int;
public static var leftAlt: Int;
public static var numPad8: Int;
public static var numLock: Int;
public static var four: Int;
public static var rightAlt: Int;
public static var pause: Int;
public static var numPad0: Int;
public static var numPadEquals: Int;
public static var enter: Int;
public static var down: Int;
public static var eight: Int;
public static var f11: Int;
public static var six: Int;
public static var r: Int;
public static var rightShift: Int;
public static var t: Int;
public static var u: Int;
public static var pageDown: Int;
public static var nine: Int;
public static var zero: Int;
public static var capsLock: Int;
public static var p: Int;
public static var leftBracket: Int;
public static var underscore: Int;
public static var scollLock: Int;
public static var minus: Int;
public static var f14: Int;
public static var m: Int;
public static var cimcumflex: Int;
public static var one: Int;
public static var up: Int;
public static var equals: Int;
public static var d: Int;
public static var f7: Int;
public static var apostrophe: Int;
public static var numPad9: Int;
public static var f15: Int;
public static var stop: Int;
public static var f10: Int;
public static var numPad7: Int;
public static var numPad3: Int;
public static var comma: Int;
public static var numPadAdd: Int;
public static var tab: Int;
public static var numPad4: Int;
public static var f3: Int;
public static var kana: Int;
public static var numPad1: Int;
public static var right: Int;
public static var numPadDecimal: Int;
public static var f2: Int;
public static var leftShift: Int;
public static var backspace: Int;
public static var convert: Int;
public static var end: Int;
public static var three: Int;
public static var kanji: Int;
public static var v: Int;
public static var colon: Int;
public static var semiColon: Int;
public static var two: Int;
public static var f13: Int;
public static var multiply: Int;
public static var period: Int;
public static var ax: Int;
public static var slash: Int;
public static var f6: Int;
public static var at: Int;
public static var numPadDivide: Int;
public static var numPad5: Int;
public static var f12: Int;
public static var f8: Int;
public static var home: Int;
public static var five: Int;
public static var numPadComma: Int;
}

15
src/cc/Multishell.hx Normal file
View File

@ -0,0 +1,15 @@
package cc;
import lua.Table;
import haxe.extern.Rest;
@:native("multishell")
extern class Multishell {
public static function getCurrent(): Int;
public static function getCount(): Int;
public static function launch(environment: Table<Dynamic, Dynamic>, path: String, args: Rest<String>): Int;
public static function setFocus(id: Int): Void;
public static function setTitle(id: Int, title: String): Void;
public static function getTitle(id: Int): String;
public static function getFocus(): Int;
}

38
src/cc/OS.hx Normal file
View File

@ -0,0 +1,38 @@
package cc;
import lua.Table;
import lua.TableTools;
import haxe.extern.Rest;
@:native("os")
extern class OS {
public static function version(): String;
public static function getComputerID(): Int;
public static function getComputerLabel(): String;
public static function setComputerLabel(label: String): Void;
public static function run(environment: Table<Dynamic, Dynamic>, path: String, args: Rest<String>): Bool;
public static function loadAPI(path: String): Bool;
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: Int): Int;
public static function cancelTimer(id: Int): Void;
public static function time(): Float;
public static function sleep(timeout: Float): Void;
public static function day(): Int;
public static function setAlarm(time: Float): Int;
public static function cancelAlarm(id: Int): Void;
public static function shutdown(): Void;
public static function reboot(): Void;
@: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): ArrayAccess<Dynamic> {
return cast TableTools.pack(_pullEvent(type));
}
public static inline function pullEventRaw(?type: String): ArrayAccess<Dynamic> {
return cast TableTools.pack(_pullEventRaw(type));
}
}

16
src/cc/PaintUtils.hx Normal file
View File

@ -0,0 +1,16 @@
package cc;
import lua.Table;
import cc.Colors;
typedef Image = Table<Int, Table<Int, Int>>;
@:native("paintutils")
extern class PaintUtils {
public static function loadImage(path: String): Image;
public static function drawImage(image: Image, x: Int, y: Int): Void;
public static function drawPixel(x: Int, y: Int, ?color: Color): Void;
public static function drawLine(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void;
public static function drawBox(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void;
public static function drawFilledBox(startX: Int, startY: Int, endX: Int, endY: Int, ?color: Color): Void;
}

10
src/cc/Parallel.hx Normal file
View File

@ -0,0 +1,10 @@
package cc;
import haxe.Constraints;
import haxe.extern.Rest;
@:native("parallel")
extern class Parallel {
public static function waitForAny(f1: Function, funcs: Rest<Function>): Int;
public static function waitForAll(f1: Function, funcs: Rest<Function>): Int;
}

16
src/cc/Peripheral.hx Normal file
View File

@ -0,0 +1,16 @@
package cc;
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 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>;
}

35
src/cc/Rednet.hx Normal file
View File

@ -0,0 +1,35 @@
package cc;
import lua.Table;
import lua.TableTools;
typedef MessageData = Dynamic;
@:multiReturn
extern class ReceivedMessage<T : MessageData> {
public var senderID: Int;
public var message: T;
public var distance: Float;
public var protocol: String;
}
@:native("rednet")
extern class Rednet {
public static function open(modem: String): Void;
public static function close(modem: String): Void;
public static function send(to: Int, data: MessageData, ?protocol: String): Void;
public static function broadcast(data: MessageData, ?protocol: String): Void;
public static function receive<T : MessageData>(?protocol: String, ?timeout: Int): ReceivedMessage<T>;
public static function isOpen(modem: String): Bool;
public static function host(protocol: String, hostname: String): Void;
public static function unhost(protocol: String, hostname: String): Void;
@:native("lookup")
private static function _lookup(protocol: String, ?hostname: String): Dynamic;
public static inline function lookup(protocol: String, ?hostname: String): Table<Int, Int> {
return TableTools.pack(_lookup(protocol, hostname));
}
public static function run(): Void;
}

19
src/cc/Redstone.hx Normal file
View File

@ -0,0 +1,19 @@
package cc;
import lua.Table;
import cc.Colors;
@:native("redstone")
extern class Redstone {
public static function getSides(): Table<Int, String>;
public static function getInput(side: String): Bool;
public static function setOutput(side: String, state: Bool): Void;
public static function getOutput(side: String): Bool;
public static function getAnalogInput(side: String): Int;
public static function setAnalogOutput(side: String, strength: Int): Void;
public static function getAnalogOutput(side: String): Int;
public static function getBundledInput(side: String): Color;
public static function setBundledOutput(side: String, state: Color): Void;
public static function getBundledOutput(side: String): Color;
public static function testBundledInput(side: String, value: Color): Bool;
}

16
src/cc/Settings.hx Normal file
View File

@ -0,0 +1,16 @@
package cc;
import lua.Table;
typedef SettingData = Dynamic;
@:native("settings")
extern class Settings {
public static function set(name: String, value: SettingData): Void;
public static function get(name: String, ?defaultValue: SettingData): SettingData;
public static function unset(name: String): Void;
public static function clear(): Void;
public static function getNames(): Table<Int, String>;
public static function load(path: String): Bool;
public static function save(path: String): Bool;
}

24
src/cc/Shell.hx Normal file
View File

@ -0,0 +1,24 @@
package cc;
import lua.Table;
import haxe.extern.Rest;
@:native("shell")
extern class Shell {
public static function exit(): Void;
public static function dir(): String;
public static function setDir(path: String): Void;
public static function path(): String;
public static function setPath(path: String): Void;
public static function resolve(localPath: String): String;
public static function resolveProgram(name: String): String;
public static function aliases(): Table<String, String>;
public static function setAlias(alias: String, program: String): Void;
public static function clearAlias(alias: String): Void;
public static function programs(?showHidden: Bool): Table<Int, String>;
public static function getRunningProgram(): String;
public static function run(command: String, args: Rest<String>): Bool;
public static function openTab(command: String, args: Rest<String>): Int;
public static function switchTab(tabID: Int): Void;
// todo: completion functions
}

54
src/cc/Term.hx Normal file
View File

@ -0,0 +1,54 @@
package cc;
import cc.Colors;
@:multiReturn
extern class TerminalPosition {
public var x: Int;
public var y: Int;
}
@:multiReturn
extern class TerminalSize {
public var width: Int;
public var height: Int;
}
extern class TerminalObject {
public function write(text: String): Void;
public function blit(text: String, colors: String, background: String): Void;
public function clear(): Void;
public function clearLine(): Void;
public function getCursorPos(): TerminalPosition;
public function setCursorPos(x: Int, y: Int): Void;
public function setCursorBlink(value: Bool): Void;
public function isColor(): Bool;
public function getSize(): TerminalSize;
public function scroll(lines: Int): Void;
public function setTextColor(color: Color): Void;
public function getTextColor(): Color;
public function setBackgroundColor(color: Color): Void;
public function getBackgroundColor(): Color;
}
@:native("term")
extern class Term {
public static function write(text: String): Void;
public static function blit(text: String, colors: String, background: String): Void;
public static function clear(): Void;
public static function clearLine(): Void;
public static function getCursorPos(): TerminalPosition;
public static function setCursorPos(x: Int, y: Int): Void;
public static function setCursorBlink(value: Bool): Void;
public static function isColor(): Bool;
public static function getSize(): TerminalSize;
public static function scroll(lines: Int): Void;
public static function setTextColor(color: Color): Void;
public static function getTextColor(): Color;
public static function setBackgroundColor(color: Color): Void;
public static function getBackgroundColor(): Color;
public static function redirect(target: TerminalObject): TerminalObject;
public static function current(): TerminalObject;
public static function native(): TerminalObject;
}

17
src/cc/TextUtils.hx Normal file
View File

@ -0,0 +1,17 @@
package cc;
typedef TextUtilsSerializable = Dynamic;
@:native("textutils")
extern class TextUtils {
public static function slowWrite(text: String, ?rate: Float): Void;
public static function slowPrint(text: String, ?rate: Float): Void;
public static function formatTime(time: Float, ?twentyFourHour: Bool): String;
// todo: tabulate, paged tabulate
public static function pagedPrint(text: String, freeLines: Int): Int;
public static function serialize(data: TextUtilsSerializable): String;
public static function unserialize<T : TextUtilsSerializable>(from: String): T;
public static function serializeJSON(data: TextUtilsSerializable, ?unquoteKeys: Bool): String;
public static function urlEncode(data: String): String;
// todo: complete
}

74
src/cc/Turtle.hx Normal file
View File

@ -0,0 +1,74 @@
package cc;
import haxe.extern.EitherType;
@:multiReturn
extern class TurtleActionResult {
public var successful: Bool;
public var error: String;
}
extern class TurtleItemDetail {
public var name: String;
public var damage: Int;
public var count: Int;
}
extern class TurtleBlockDetail {
public var name: String;
public var metadata: Int;
public var state: Dynamic;
}
@:multiReturn
extern class TurtleInspectResult {
public var successful: Bool;
public var result: EitherType<String, TurtleBlockDetail>;
}
@:native("turtle")
extern class Turtle {
public static function craft(qty: Int): TurtleActionResult;
public static function forward(): TurtleActionResult;
public static function back(): TurtleActionResult;
public static function up(): TurtleActionResult;
public static function down(): TurtleActionResult;
public static function turnLeft(): TurtleActionResult;
public static function turnRight(): TurtleActionResult;
public static function select(slot: Int): Bool;
public static function getSelectedSlot(): Int;
public static function getItemCount(?slot: Int): Int;
public static function getItemSpace(?slot: Int): Int;
public static function getItemDetail(?slot: Int): TurtleItemDetail;
public static function equipLeft(): TurtleActionResult;
public static function equipRight(): TurtleActionResult;
public static function attack(): TurtleActionResult;
public static function attackUp(): TurtleActionResult;
public static function attackDown(): TurtleActionResult;
public static function dig(): TurtleActionResult;
public static function digUp(): TurtleActionResult;
public static function digDown(): TurtleActionResult;
public static function place(?signText: String): TurtleActionResult;
public static function placeUp(): TurtleActionResult;
public static function placeDown(): TurtleActionResult;
public static function detect(): Bool;
public static function detectUp(): Bool;
public static function detectDown(): Bool;
public static function inspect(): TurtleInspectResult;
public static function inspectUp(): TurtleInspectResult;
public static function inspectDown(): TurtleInspectResult;
public static function compare(): Bool;
public static function compareUp(): Bool;
public static function compareDown(): Bool;
public static function compareTo(slot: Int): Bool;
public static function drop(?count: Int): TurtleActionResult;
public static function dropUp(?count: Int): TurtleActionResult;
public static function dropDown(?count: Int): TurtleActionResult;
public static function suck(?amount: Int): TurtleActionResult;
public static function suckUp(?amount: Int): TurtleActionResult;
public static function suckDown(?amount: Int): TurtleActionResult;
public static function refuel(?qty: Int): TurtleActionResult;
public static function getFuelLevel(): Int;
public static function getFuelLimit(): Int;
public static function transferTo(to: Int, ?qty: Int): Bool;
}

16
src/cc/Vector.hx Normal file
View File

@ -0,0 +1,16 @@
package cc;
@:native("vector")
extern class Vector {
@:native("new") public static function create(x: Int, y: Int, z: Int): Vector;
public function add(other: Vector): Vector;
public function sub(other: Vector): Vector;
public function mul(n: Float): Vector;
public function dot(other: Vector): Float;
public function cross(other: Vector): Float;
public function length(): Float;
public function normalize(): Vector;
public function round(): Vector;
@:native("tostring") public function toString(): String;
}

15
src/cc/Window.hx Normal file
View File

@ -0,0 +1,15 @@
package cc;
import cc.Term;
@:native("window")
@:luaDotMethod
extern class Window extends TerminalObject {
public static function create(parent: TerminalObject, x: Int, y: Int, width: Int, height: Int, ?visible: Bool): Window;
public function setVisible(visible: Bool): Void;
public function redraw(): Void;
public function restoreCursor(): Void;
public function getPosition(): TerminalPosition;
public function reposition(x: Int, y: Int, ?width: Int, ?height: Int): Void;
}