Add HTTP lib and globals

This commit is contained in:
apemanzilla 2018-03-24 15:01:41 -04:00
parent c3ee593f86
commit 808c1972a9
4 changed files with 36 additions and 2 deletions

View File

View File

@ -4,9 +4,9 @@
"license": "MIT",
"tags": ["computercraft", "cc", "minecraft", "lua"],
"description": "Bindings for the Lua APIs of the ComputerCraft mod for Minecraft",
"version": "1.0.0",
"version": "1.0.1",
"classPath": "src",
"releasenote": "Initial release",
"releasenote": "Adds missing HTTP api and globals (in ComputerCraft class)",
"contributors": [
"apemanzilla"
]

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

@ -0,0 +1,10 @@
package src.cc;
@: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;
}

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

@ -0,0 +1,24 @@
package src.cc;
import lua.Table;
@:multiReturn
extern class HTTPCheckReturn {
public var allowed: Bool;
public var error: Null<String>;
}
extern class HTTPResponse {
public function close(): Void;
public function readLine(): String;
public function readAll(): String;
public function getResponseCode(): Int;
}
@:native("http")
extern class HTTP {
public static function checkURL(url: String): Bool;
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>;
}