M13.7: ScriptUI resource strings, onDraw graphics, live onChanging, Socket

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-03 05:49:05 -04:00
co-authored by Claude Opus 5.5
parent da6cc851b4
commit 5aae82b05c
10 changed files with 995 additions and 27 deletions
+72 -2
View File
@@ -166,7 +166,7 @@ File.prototype = {
read: function (n) {
if (this.__buf === null) this.open("r");
if (this.__buf === null) return "";
var s = n === undefined ? this.__buf.substring(this.__pos) : this.__buf.substr(this.__pos, n);
var s = n === undefined ? this.__buf.substring(this.__pos) : this.__buf.substring(this.__pos, this.__pos + n);
this.__pos += s.length;
return s;
},
@@ -255,7 +255,77 @@ Object.defineProperty(Folder, "temp", { get: function () { return null; } });
Object.defineProperty(Folder, "desktop", { get: function () { return null; } });
Object.defineProperty(Folder, "myDocuments", { get: function () { return null; } });
function Socket() { __file("network", ""); }
// TCP sockets (behind Allow Scripts to Write Files and Access Network; see socket.rs).
function Socket() {
if (!(this instanceof Socket)) return new Socket();
__sock("check", 0, "{}");
this.__id = 0;
this.host = "";
this.timeout = 10;
this.encoding = "ASCII";
this.error = "";
}
function __sockCall(s, op, extra) {
var p = extra || {};
p.timeout = s.timeout;
p.encoding = s.encoding;
var r = JSON.parse(__sock(op, s.__id, JSON.stringify(p)));
s.error = r.error || "";
return r;
}
Socket.prototype = {
constructor: Socket,
get connected() { return this.__id > 0 && __sockCall(this, "connected").value === true; },
get eof() { return this.__id === 0 || __sockCall(this, "eof").value === true; },
open: function (host, encoding) {
if (this.__id) this.close();
if (encoding) this.encoding = String(encoding);
var r = __sockCall(this, "open", { host: String(host) });
if (r.error) return false;
this.__id = r.id;
this.host = String(host);
return true;
},
listen: function (port, encoding) {
if (this.__id) this.close();
if (encoding) this.encoding = String(encoding);
var r = __sockCall(this, "listen", { port: __num(port, "port") });
if (r.error) return false;
this.__id = r.id;
this.host = "127.0.0.1:" + r.port;
this.port = r.port;
return true;
},
poll: function () {
if (!this.__id) return null;
var r = __sockCall(this, "poll");
if (r.id === null || r.id === undefined) return null;
var s = Object.create(Socket.prototype);
s.__id = r.id;
s.host = r.host || "";
s.timeout = this.timeout;
s.encoding = this.encoding;
s.error = "";
return s;
},
read: function (count) {
if (!this.__id) return "";
return __sockCall(this, "read", { count: count === undefined ? -1 : __num(count, "count") }).data || "";
},
readln: function () { return this.__id ? __sockCall(this, "readln").data || "" : ""; },
write: function () {
if (!this.__id) return false;
var s = Array.prototype.slice.call(arguments).map(__str).join("");
return !__sockCall(this, "write", { data: s }).error;
},
writeln: function () { return this.write(Array.prototype.slice.call(arguments).map(__str).join("") + "\n"); },
close: function () {
if (this.__id) __sockCall(this, "close");
this.__id = 0;
return true;
},
toString: function () { return "[object Socket]"; }
};
var system = { callSystem: function () { throw __err("scripts can't run system commands"); } };
// ------------------------------------------------------------------ helpers