Skip to content

Commit

Permalink
Improve jrunscript io definitions
Browse files Browse the repository at this point in the history
Also:
* fix broken documentation link for jsh loader
  • Loading branch information
davidpcaldwell committed Sep 19, 2024
1 parent b7de3f8 commit 4a3231c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jrunscript/jsh/_.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace slime.jsh {
* of a script. It has two implementations: a Rhino implementation (`inonit.script.jsh.Rhino`) and a Nashorn implementation
* (`inonit.script.jsh.Nashorn`); the entry point is chosen and executed by the launcher subsystem.
*
* It is documented at {@link slime.jsh.loader.internal}.
* It is documented at {@link slime.jsh.internal.loader}.
*
* ## Development Tools
*
Expand Down
9 changes: 8 additions & 1 deletion loader/jrunscript/io.fifty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
namespace slime.jrunscript.runtime.io {
type byte = number

export namespace input {
export interface ReaderConfiguration {
charset: string
LINE_SEPARATOR: string
}
}

/**
* A stream from which bytes may be read.
*/
export interface InputStream {
/** A character input stream that reads this stream. */
character: (mode?: any) => Reader
character: (mode?: input.ReaderConfiguration) => Reader

/**
* Closes the underlying stream.
Expand Down
12 changes: 10 additions & 2 deletions loader/jrunscript/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
var _java = $context._streams;

function InputStream(peer) {
/**
*
* @param { slime.jrunscript.runtime.io.input.ReaderConfiguration } [mode]
* @returns
*/
var character = function(mode) {
if (!mode) mode = {};
if (!mode.charset) mode.charset = Packages.java.nio.charset.Charset.defaultCharset().name();
if (!mode) mode = {
charset: void(0),
LINE_SEPARATOR: void(0)
};
if (!mode.charset) mode.charset = String(Packages.java.nio.charset.Charset.defaultCharset().name());
var separator = mode.LINE_SEPARATOR;
// TODO No unit test for this method currently; does it work?
return Reader(new Packages.java.io.InputStreamReader(peer,mode.charset), {LINE_SEPARATOR: separator});
Expand Down

0 comments on commit 4a3231c

Please sign in to comment.