From 04a4b8ed876addffab17fefa7c853c728053e833 Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Sat, 11 Nov 2023 21:43:48 +1000 Subject: [PATCH] getBuffer for future io redirects --- clite/core.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/clite/core.js b/clite/core.js index cddb8b4..10a581a 100644 --- a/clite/core.js +++ b/clite/core.js @@ -1464,6 +1464,28 @@ clite.lib = { return 0; } return 0; + }, + getBuffer:function() { + return Object.create({ + buffer:{ + data:'', + pos:0 + }, + read:function() { + if (this.buffer.pos >= this.buffer.data.length) + return null; + var b = this.data.buffer.substring(this.buffer.pos,this.buffer.data.length-this.buffer.pos); + var i = b.indexOf('\n'); + if (b < 0) + return b; + return b.substring(0,i); + }, + write:function(txt) { + this.buffer.data += txt; + } + }); + }, + exec:function(args,io) { } } clite.lib.api = { // this is passed to programs via include('stdlib') @@ -1471,5 +1493,6 @@ clite.lib.api = { // this is passed to programs via include('stdlib') dirname:clite.lib.dirname, resolvePath:clite.lib.resolvePath, getFileType:clite.lib.getFileType, - strToArgs:clite.lib.strToArgs + strToArgs:clite.lib.strToArgs, + exec:clite.lib.exec };