structscript 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/interpreter.js +20 -1
  2. package/package.json +1 -1
@@ -62,6 +62,25 @@ class Interpreter {
62
62
  G.define('print', a => { this.outputFn(a.map(x => this._str(x)).join(' ')); return null; });
63
63
  G.define('warn', a => { this.warnFn(this._str(a[0])); return null; });
64
64
 
65
+ // input(prompt?) — synchronous stdin read, works like Python's input()
66
+ G.define('input', a => {
67
+ const prompt = a[0] !== undefined ? this._str(a[0]) : '';
68
+ if (prompt) process.stdout.write(prompt);
69
+ // Read synchronously from stdin one byte at a time until newline
70
+ const buf = Buffer.alloc(1);
71
+ let result = '';
72
+ while (true) {
73
+ let bytesRead = 0;
74
+ try { bytesRead = require('fs').readSync(process.stdin.fd, buf, 0, 1, null); }
75
+ catch (e) { break; }
76
+ if (bytesRead === 0) break;
77
+ const ch = buf.toString('utf8');
78
+ if (ch === '\n') break;
79
+ if (ch !== '\r') result += ch;
80
+ }
81
+ return result;
82
+ });
83
+
65
84
  // Math
66
85
  G.define('abs', a => Math.abs(a[0]));
67
86
  G.define('sqrt', a => Math.sqrt(a[0]));
@@ -717,4 +736,4 @@ class Interpreter {
717
736
  }
718
737
  }
719
738
 
720
- module.exports = { Interpreter, SSError, Environment };
739
+ module.exports = { Interpreter, SSError, Environment };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "structscript",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "The StructScript programming language — clean, readable scripting for everyone",
5
5
  "keywords": ["structscript", "language", "interpreter", "scripting", "programming-language"],
6
6
  "author": "StructScript",