Compare commits

...

15 Commits

9 changed files with 46 additions and 15 deletions

View File

@@ -2,8 +2,7 @@ package cc;
import lua.Table;
@:enum
abstract OpenFileMode(String) {
enum abstract OpenFileMode(String) {
var Read = "r";
var Write = "w";
var Append = "a";
@@ -16,11 +15,14 @@ abstract OpenFileMode(String) {
extern class FileHandle {
public function readLine(?withTrailing:Bool):Null<String>;
public function readAll():Null<String>;
public function read(?count:Int):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 write(data:String):Void;
public function writeLine(data:String):Void;
public function flush():Void;
public function seek(?whence:String, ?offset:Int):Void;
public function seek(?whence:String, ?offset:Int):Int;
public function close():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:Int):Int;
public static function startTimer(timeout:Float):Int;
public static function cancelTimer(id:Int):Void;
public static function time():Float;
public static function sleep(timeout:Float):Void;
@@ -24,6 +24,8 @@ 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;

View File

@@ -1,16 +1,22 @@
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 getType(name:String):String;
public static function getMethods(name:String):Table<String, Function>;
public static function getMethods(name:String):Table<Int,String>;
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));
}
}

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

@@ -0,0 +1,13 @@
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

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

View File

@@ -5,6 +5,7 @@ import lua.Table;
interface ReducedItemInfo {
public var count:Int;
public var name:String;
public var nbt:Null<String>;
}
interface DetailedItemInfo extends ReducedItemInfo {
@@ -12,6 +13,10 @@ interface DetailedItemInfo extends ReducedItemInfo {
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 {
@@ -20,4 +25,5 @@ extern class ItemStorage {
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

@@ -2,7 +2,7 @@ package cc.periphs;
import lua.Table;
extern class Modem {
@: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.

View File

@@ -1,5 +1,7 @@
package cc.periphs;
import cc.Term.TerminalSize;
@:multiReturn
extern class Position {
var x:Int;
@@ -15,7 +17,7 @@ extern class ColorData {
var b:Float;
}
extern class Monitor {
@: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.
@@ -24,7 +26,7 @@ extern class Monitor {
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():Int; // Get the size of the terminal.
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.

View File

@@ -1,16 +1,16 @@
package cc.periphs;
@:multiReturn
extern class Position {
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():Position; // Returns the current position of the cursor on the 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():Position; // Returns the size of the current 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.